elysia 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,16 +22,16 @@
22
22
  "import { Kind, TSchema } from '@sinclair/typebox'\nimport { Value } from '@sinclair/typebox/value'\nimport { TypeCheck, TypeCompiler } from '@sinclair/typebox/compiler'\n\nimport { t } from '.'\nimport { isNotEmpty } from './handler'\n\nimport type {\n\tLifeCycleStore,\n\tLocalHook,\n\tMaybeArray,\n\tInputSchema,\n\tBaseMacro,\n\tLifeCycleType,\n\tHookContainer,\n\tGracefulHandler,\n\tPreHandler,\n\tBodyHandler,\n\tTransformHandler,\n\tOptionalHandler,\n\tAfterHandler,\n\tMapResponse,\n\tVoidHandler,\n\tErrorHandler\n} from './types'\nimport type { CookieOptions } from './cookies'\nimport { Sucrose } from './sucrose'\n\nexport const replaceUrlPath = (url: string, pathname: string) => {\n\tconst urlObject = new URL(url)\n\turlObject.pathname = pathname\n\treturn urlObject.toString()\n}\n\nconst isClass = (v: Object) =>\n\t(typeof v === 'function' && /^\\s*class\\s+/.test(v.toString())) ||\n\t// Handle import * as Sentry from '@sentry/bun'\n\t// This also handle [object Date], [object Array]\n\t// and FFI value like [object Prisma]\n\tv.toString().startsWith('[object ') ||\n\t// If object prototype is not pure, then probably a class-like object\n\tisNotEmpty(Object.getPrototypeOf(v))\n\nconst isObject = (item: any): item is Object =>\n\titem && typeof item === 'object' && !Array.isArray(item)\n\nexport const mergeDeep = <\n\tA extends Record<string, any>,\n\tB extends Record<string, any>\n>(\n\ttarget: A,\n\tsource: B,\n\t{\n\t\tskipKeys\n\t}: {\n\t\tskipKeys?: string[]\n\t} = {}\n): A & B => {\n\tif (isObject(target) && isObject(source))\n\t\tfor (const [key, value] of Object.entries(source)) {\n\t\t\tif (skipKeys?.includes(key)) continue\n\n\t\t\tif (!isObject(value) || !(key in target) || isClass(value)) {\n\t\t\t\ttarget[key as keyof typeof target] = value\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\ttarget[key as keyof typeof target] = mergeDeep(\n\t\t\t\t(target as any)[key] as any,\n\t\t\t\tvalue\n\t\t\t)\n\t\t}\n\n\treturn target as A & B\n}\nexport const mergeCookie = <const A extends Object, const B extends Object>(\n\ta: A,\n\tb: B\n): A & B => {\n\t// @ts-ignore\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tconst { properties: _, ...target } = a ?? {}\n\n\t// @ts-ignore\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tconst { properties: __, ...source } = b ?? {}\n\n\treturn mergeDeep(target, source) as A & B\n}\n\nexport const mergeObjectArray = <T extends HookContainer>(\n\ta: T | T[] = [],\n\tb: T | T[] = []\n): T[] => {\n\tif (!a) return []\n\tif (!b) return a as any\n\n\t// ! Must copy to remove side-effect\n\tconst array = <T[]>[]\n\tconst checksums = <(number | undefined)[]>[]\n\n\tif (!Array.isArray(a)) a = [a]\n\tif (!Array.isArray(b)) b = [b]\n\n\tfor (const item of a) {\n\t\tarray.push(item)\n\n\t\tif (item.checksum) checksums.push(item.checksum)\n\t}\n\n\tfor (const item of b)\n\t\tif (!checksums.includes(item.checksum)) array.push(item)\n\n\treturn array\n}\n\nexport const primitiveHooks = [\n\t'start',\n\t'request',\n\t'parse',\n\t'transform',\n\t'resolve',\n\t'beforeHandle',\n\t'afterHandle',\n\t'onResponse',\n\t'mapResponse',\n\t'trace',\n\t'error',\n\t'stop',\n\t'body',\n\t'headers',\n\t'params',\n\t'query',\n\t'response',\n\t'type',\n\t'detail'\n] as const\n\nconst primitiveHookMap = primitiveHooks.reduce(\n\t(acc, x) => ((acc[x] = true), acc),\n\t{} as Record<string, boolean>\n)\n\nexport const mergeResponse = (\n\ta: InputSchema['response'],\n\tb: InputSchema['response']\n) => {\n\t// If both are Record<number, ...> then merge them,\n\t// giving preference to b.\n\ttype RecordNumber = Record<number, any>\n\tconst isRecordNumber = (x: typeof a | typeof b): x is RecordNumber =>\n\t\ttypeof x === 'object' && Object.keys(x).every(isNumericString)\n\n\tif (isRecordNumber(a) && isRecordNumber(b))\n\t\treturn { ...(a as RecordNumber), ...(b as RecordNumber) }\n\n\treturn b ?? a\n}\n\nexport const mergeHook = (\n\ta?: LifeCycleStore,\n\tb?: LocalHook<any, any, any, any, any, any, any>,\n\t{ allowMacro = false }: { allowMacro?: boolean } = {}\n): LifeCycleStore => {\n\t// In case if merging union is need\n\t// const customAStore: Record<string, unknown> = {}\n\t// const customBStore: Record<string, unknown> = {}\n\n\t// for (const [key, value] of Object.entries(a)) {\n\t// \tif (primitiveHooks.includes(key as any)) continue\n\n\t// \tcustomAStore[key] = value\n\t// }\n\n\t// for (const [key, value] of Object.entries(b)) {\n\t// \tif (primitiveHooks.includes(key as any)) continue\n\n\t// \tcustomBStore[key] = value\n\t// }\n\n\t// const unioned = Object.keys(customAStore).filter((x) =>\n\t// \tObject.keys(customBStore).includes(x)\n\t// )\n\n\t// // Must provide empty object to prevent reference side-effect\n\t// const customStore = Object.assign({}, customAStore, customBStore)\n\n\t// for (const union of unioned)\n\t// \tcustomStore[union] = mergeObjectArray(\n\t// \t\tcustomAStore[union],\n\t// \t\tcustomBStore[union]\n\t// \t)\n\n\tconst rest = allowMacro\n\t\t? {\n\t\t\t\t...a,\n\t\t\t\t...b\n\t\t }\n\t\t: undefined\n\n\treturn {\n\t\t...rest,\n\t\t// Merge local hook first\n\t\t// @ts-ignore\n\t\tbody: b?.body ?? a?.body,\n\t\t// @ts-ignore\n\t\theaders: b?.headers ?? a?.headers,\n\t\t// @ts-ignore\n\t\tparams: b?.params ?? a?.params,\n\t\t// @ts-ignore\n\t\tquery: b?.query ?? a?.query,\n\t\t// ? This order is correct - SaltyAom\n\t\tresponse: mergeResponse(\n\t\t\t// @ts-ignore\n\t\t\ta?.response,\n\t\t\t// @ts-ignore\n\t\t\tb?.response\n\t\t),\n\t\ttype: a?.type || b?.type,\n\t\tdetail: mergeDeep(\n\t\t\t// @ts-ignore\n\t\t\tb?.detail ?? {},\n\t\t\t// @ts-ignore\n\t\t\ta?.detail ?? {}\n\t\t),\n\t\tparse: mergeObjectArray(a?.parse as any, b?.parse),\n\t\ttransform: mergeObjectArray(a?.transform, b?.transform),\n\t\tbeforeHandle: mergeObjectArray(a?.beforeHandle, b?.beforeHandle),\n\t\tafterHandle: mergeObjectArray(a?.afterHandle, b?.afterHandle),\n\t\tonResponse: mergeObjectArray(a?.onResponse, b?.onResponse) as any,\n\t\tmapResponse: mergeObjectArray(a?.mapResponse, b?.mapResponse) as any,\n\t\ttrace: mergeObjectArray(a?.trace, b?.trace) as any,\n\t\terror: mergeObjectArray(a?.error, b?.error)\n\t}\n}\n\nexport const getSchemaValidator = (\n\ts: TSchema | string | undefined,\n\t{\n\t\tmodels = {},\n\t\tdynamic = false,\n\t\tnormalize = false,\n\t\tadditionalProperties = normalize\n\t}: {\n\t\tmodels?: Record<string, TSchema>\n\t\tadditionalProperties?: boolean\n\t\tdynamic?: boolean\n\t\tnormalize?: boolean\n\t}\n) => {\n\tif (!s) return\n\tif (typeof s === 'string' && !(s in models)) return\n\n\tconst schema: TSchema = typeof s === 'string' ? models[s] : s\n\n\t// @ts-ignore\n\tif (schema.type === 'object' && 'additionalProperties' in schema === false)\n\t\tschema.additionalProperties = additionalProperties\n\n\tconst cleaner = (value: unknown) => Value.Clean(schema, value)\n\n\tif (dynamic) {\n\t\tconst validator = {\n\t\t\tschema,\n\t\t\treferences: '',\n\t\t\tcheckFunc: () => {},\n\t\t\tcode: '',\n\t\t\tCheck: (value: unknown) => Value.Check(schema, value),\n\t\t\tErrors: (value: unknown) => Value.Errors(schema, value),\n\t\t\tCode: () => ''\n\t\t} as unknown as TypeCheck<TSchema>\n\n\t\tif (normalize && schema.additionalProperties === true)\n\t\t\t// @ts-ignore\n\t\t\tvalidator.Clean = cleaner\n\n\t\t// @ts-ignore\n\t\tif (schema.config) {\n\t\t\t// @ts-ignore\n\t\t\tvalidator.config = schema.config\n\n\t\t\t// @ts-ignore\n\t\t\tif (validator?.schema?.config)\n\t\t\t\t// @ts-ignore\n\t\t\t\tdelete validator.schema.config\n\t\t}\n\n\t\treturn validator\n\t}\n\n\tconst compiled = TypeCompiler.Compile(schema, Object.values(models))\n\n\t// @ts-expect-error\n\tcompiled.Clean = cleaner\n\n\t// @ts-ignore\n\tif (schema.config) {\n\t\t// @ts-ignore\n\t\tcompiled.config = schema.config\n\n\t\t// @ts-ignore\n\t\tif (compiled?.schema?.config)\n\t\t\t// @ts-ignore\n\t\t\tdelete compiled.schema.config\n\t}\n\n\treturn compiled\n}\n\nexport const getResponseSchemaValidator = (\n\ts: InputSchema['response'] | undefined,\n\t{\n\t\tmodels = {},\n\t\tdynamic = false,\n\t\tnormalize = false,\n\t\tadditionalProperties = normalize\n\t}: {\n\t\tmodels?: Record<string, TSchema>\n\t\tadditionalProperties?: boolean\n\t\tdynamic?: boolean\n\t\tnormalize?: boolean\n\t}\n): Record<number, TypeCheck<any>> | undefined => {\n\tif (!s) return\n\tif (typeof s === 'string' && !(s in models)) return\n\n\tconst maybeSchemaOrRecord = typeof s === 'string' ? models[s] : s\n\n\tconst compile = (schema: TSchema, references?: TSchema[]) => {\n\t\t// eslint-disable-next-line sonarjs/no-identical-functions\n\t\t// Sonar being delulu, schema is not identical\n\t\tconst cleaner = (value: unknown) => Value.Clean(schema, value)\n\n\t\tif (dynamic)\n\t\t\treturn {\n\t\t\t\tschema,\n\t\t\t\treferences: '',\n\t\t\t\tcheckFunc: () => {},\n\t\t\t\tcode: '',\n\t\t\t\tCheck: (value: unknown) => Value.Check(schema, value),\n\t\t\t\tErrors: (value: unknown) => Value.Errors(schema, value),\n\t\t\t\tCode: () => ''\n\t\t\t} as unknown as TypeCheck<TSchema>\n\n\t\tconst compiledValidator = TypeCompiler.Compile(schema, references)\n\n\t\tif (normalize && schema.additionalProperties === true)\n\t\t\t// @ts-ignore\n\t\t\tcompiledValidator.Clean = cleaner\n\n\t\treturn compiledValidator\n\t}\n\n\tif (Kind in maybeSchemaOrRecord) {\n\t\tif ('additionalProperties' in maybeSchemaOrRecord === false)\n\t\t\tmaybeSchemaOrRecord.additionalProperties = additionalProperties\n\n\t\treturn {\n\t\t\t200: compile(maybeSchemaOrRecord, Object.values(models))\n\t\t}\n\t}\n\n\tconst record: Record<number, TypeCheck<any>> = {}\n\n\tObject.keys(maybeSchemaOrRecord).forEach((status): TSchema | undefined => {\n\t\tconst maybeNameOrSchema = maybeSchemaOrRecord[+status]\n\n\t\tif (typeof maybeNameOrSchema === 'string') {\n\t\t\tif (maybeNameOrSchema in models) {\n\t\t\t\tconst schema = models[maybeNameOrSchema]\n\t\t\t\tschema.type === 'object' &&\n\t\t\t\t\t'additionalProperties' in schema === false\n\n\t\t\t\t// Inherits model maybe already compiled\n\t\t\t\trecord[+status] =\n\t\t\t\t\tKind in schema\n\t\t\t\t\t\t? compile(schema, Object.values(models))\n\t\t\t\t\t\t: schema\n\t\t\t}\n\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (\n\t\t\tmaybeNameOrSchema.type === 'object' &&\n\t\t\t'additionalProperties' in maybeNameOrSchema === false\n\t\t)\n\t\t\tmaybeNameOrSchema.additionalProperties = additionalProperties\n\n\t\t// Inherits model maybe already compiled\n\t\trecord[+status] =\n\t\t\tKind in maybeNameOrSchema\n\t\t\t\t? compile(maybeNameOrSchema, Object.values(models))\n\t\t\t\t: maybeNameOrSchema\n\t})\n\n\treturn record\n}\n\nconst isBun = typeof Bun !== 'undefined'\nconst hasHash = isBun && typeof Bun.hash === 'function'\n\n// https://stackoverflow.com/a/52171480\nexport const checksum = (s: string) => {\n\tif (hasHash) return Bun.hash(s) as number\n\n\tlet h = 9\n\n\tfor (let i = 0; i < s.length; ) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9)\n\n\treturn (h = h ^ (h >>> 9))\n}\n\nexport const getCookieValidator = ({\n\tvalidator,\n\tdefaultConfig = {},\n\tconfig,\n\tdynamic,\n\tmodels\n}: {\n\tvalidator: TSchema | string | undefined\n\tdefaultConfig: CookieOptions | undefined\n\tconfig: CookieOptions\n\tdynamic: boolean\n\tmodels: Record<string, TSchema> | undefined\n}) => {\n\tlet cookieValidator = getSchemaValidator(validator, {\n\t\tdynamic,\n\t\tmodels,\n\t\tadditionalProperties: true\n\t})\n\n\tif (isNotEmpty(defaultConfig)) {\n\t\tif (cookieValidator) {\n\t\t\t// @ts-expect-error private\n\t\t\tcookieValidator.config = mergeCookie(\n\t\t\t\t// @ts-expect-error private\n\t\t\t\tcookieValidator.config,\n\t\t\t\tconfig\n\t\t\t)\n\t\t} else {\n\t\t\tcookieValidator = getSchemaValidator(t.Cookie({}), {\n\t\t\t\tdynamic,\n\t\t\t\tmodels,\n\t\t\t\tadditionalProperties: true\n\t\t\t})\n\n\t\t\t// @ts-expect-error private\n\t\t\tcookieValidator.config = defaultConfig\n\t\t}\n\t}\n\n\treturn cookieValidator\n}\n\nexport const mergeLifeCycle = (\n\ta: LifeCycleStore,\n\tb: LifeCycleStore | LocalHook<any, any, any, any, any, any, any>,\n\tchecksum?: number\n): LifeCycleStore => {\n\tconst injectChecksum = (x: MaybeArray<HookContainer> | undefined) => {\n\t\tif (!x) return\n\n\t\tif (!Array.isArray(x)) {\n\t\t\t// ? clone fn is required to prevent side-effect from changing hookType\n\t\t\tconst fn = x\n\n\t\t\tif (checksum && !fn.checksum) fn.checksum = checksum\n\t\t\tif (fn.scope === 'scoped') fn.scope = 'local'\n\n\t\t\treturn fn\n\t\t}\n\n\t\t// ? clone fns is required to prevent side-effect from changing hookType\n\t\tconst fns = [...x]\n\n\t\tfor (const fn of fns) {\n\t\t\tif (checksum && !fn.checksum) fn.checksum = checksum\n\n\t\t\tif (fn.scope === 'scoped') fn.scope = 'local'\n\t\t}\n\n\t\treturn fns\n\t}\n\n\treturn {\n\t\t// ...a,\n\t\t// ...b,\n\t\tstart: mergeObjectArray(\n\t\t\ta.start,\n\t\t\tinjectChecksum(b?.start)\n\t\t) as HookContainer<GracefulHandler<any>>[],\n\t\trequest: mergeObjectArray(\n\t\t\ta.request,\n\t\t\tinjectChecksum(b?.request)\n\t\t) as HookContainer<PreHandler<any, any>>[],\n\t\tparse: mergeObjectArray(\n\t\t\ta.parse,\n\t\t\tinjectChecksum(b?.parse)\n\t\t) as HookContainer<BodyHandler<any, any>>[],\n\t\ttransform: mergeObjectArray(\n\t\t\ta.transform,\n\t\t\tinjectChecksum(b?.transform)\n\t\t) as HookContainer<TransformHandler<any, any>>[],\n\t\tbeforeHandle: mergeObjectArray(\n\t\t\ta.beforeHandle,\n\t\t\tinjectChecksum(b?.beforeHandle)\n\t\t) as HookContainer<OptionalHandler<any, any>>[],\n\t\tafterHandle: mergeObjectArray(\n\t\t\ta.afterHandle,\n\t\t\tinjectChecksum(b?.afterHandle)\n\t\t) as HookContainer<AfterHandler<any, any>>[],\n\t\tmapResponse: mergeObjectArray(\n\t\t\ta.mapResponse,\n\t\t\tinjectChecksum(b?.mapResponse)\n\t\t) as HookContainer<MapResponse<any, any>>[],\n\t\tonResponse: mergeObjectArray(\n\t\t\ta.onResponse,\n\t\t\tinjectChecksum(b?.onResponse)\n\t\t) as HookContainer<VoidHandler<any, any>>[],\n\t\t// Already merged on Elysia._use, also logic is more complicated, can't directly merge\n\t\ttrace: a.trace,\n\t\terror: mergeObjectArray(\n\t\t\ta.error,\n\t\t\tinjectChecksum(b?.error)\n\t\t) as HookContainer<ErrorHandler<any, any, any>>[],\n\t\tstop: mergeObjectArray(\n\t\t\ta.stop,\n\t\t\tinjectChecksum(b?.stop)\n\t\t) as HookContainer<GracefulHandler<any>>[]\n\t}\n}\n\nexport const asHookType = (\n\tfn: HookContainer,\n\tinject: LifeCycleType,\n\t{ skipIfHasType = false }: { skipIfHasType?: boolean } = {}\n) => {\n\tif (!fn) return fn\n\n\tif (!Array.isArray(fn)) {\n\t\tif (skipIfHasType) fn.scope ??= inject\n\t\telse fn.scope = inject\n\n\t\treturn fn\n\t}\n\n\tfor (const x of fn)\n\t\tif (skipIfHasType) x.scope ??= inject\n\t\telse x.scope = inject\n\n\treturn fn\n}\n\nconst filterGlobal = (fn: MaybeArray<HookContainer>) => {\n\tif (!fn) return fn\n\n\tif (!Array.isArray(fn))\n\t\tswitch (fn.scope) {\n\t\t\tcase 'global':\n\t\t\tcase 'scoped':\n\t\t\t\treturn { ...fn }\n\n\t\t\tdefault:\n\t\t\t\treturn { fn }\n\t\t}\n\n\tconst array = <any>[]\n\n\tfor (const x of fn)\n\t\tswitch (x.scope) {\n\t\t\tcase 'global':\n\t\t\tcase 'scoped':\n\t\t\t\tarray.push({\n\t\t\t\t\t...x\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t}\n\n\treturn array\n}\n\nexport const filterGlobalHook = (\n\thook: LocalHook<any, any, any, any, any, any, any>\n): LocalHook<any, any, any, any, any, any, any> => {\n\treturn {\n\t\t// rest is validator\n\t\t...hook,\n\t\ttype: hook?.type,\n\t\tdetail: hook?.detail,\n\t\tparse: filterGlobal(hook?.parse),\n\t\ttransform: filterGlobal(hook?.transform),\n\t\tbeforeHandle: filterGlobal(hook?.beforeHandle),\n\t\tafterHandle: filterGlobal(hook?.afterHandle),\n\t\tonResponse: filterGlobal(hook?.onResponse),\n\t\terror: filterGlobal(hook?.error),\n\t\tmapResponse: filterGlobal(hook?.mapResponse)\n\t} as LocalHook<any, any, any, any, any, any, any>\n}\n\nexport const StatusMap = {\n\tContinue: 100,\n\t'Switching Protocols': 101,\n\tProcessing: 102,\n\t'Early Hints': 103,\n\tOK: 200,\n\tCreated: 201,\n\tAccepted: 202,\n\t'Non-Authoritative Information': 203,\n\t'No Content': 204,\n\t'Reset Content': 205,\n\t'Partial Content': 206,\n\t'Multi-Status': 207,\n\t'Already Reported': 208,\n\t'Multiple Choices': 300,\n\t'Moved Permanently': 301,\n\tFound: 302,\n\t'See Other': 303,\n\t'Not Modified': 304,\n\t'Temporary Redirect': 307,\n\t'Permanent Redirect': 308,\n\t'Bad Request': 400,\n\tUnauthorized: 401,\n\t'Payment Required': 402,\n\tForbidden: 403,\n\t'Not Found': 404,\n\t'Method Not Allowed': 405,\n\t'Not Acceptable': 406,\n\t'Proxy Authentication Required': 407,\n\t'Request Timeout': 408,\n\tConflict: 409,\n\tGone: 410,\n\t'Length Required': 411,\n\t'Precondition Failed': 412,\n\t'Payload Too Large': 413,\n\t'URI Too Long': 414,\n\t'Unsupported Media Type': 415,\n\t'Range Not Satisfiable': 416,\n\t'Expectation Failed': 417,\n\t\"I'm a teapot\": 418,\n\t'Misdirected Request': 421,\n\t'Unprocessable Content': 422,\n\tLocked: 423,\n\t'Failed Dependency': 424,\n\t'Too Early': 425,\n\t'Upgrade Required': 426,\n\t'Precondition Required': 428,\n\t'Too Many Requests': 429,\n\t'Request Header Fields Too Large': 431,\n\t'Unavailable For Legal Reasons': 451,\n\t'Internal Server Error': 500,\n\t'Not Implemented': 501,\n\t'Bad Gateway': 502,\n\t'Service Unavailable': 503,\n\t'Gateway Timeout': 504,\n\t'HTTP Version Not Supported': 505,\n\t'Variant Also Negotiates': 506,\n\t'Insufficient Storage': 507,\n\t'Loop Detected': 508,\n\t'Not Extended': 510,\n\t'Network Authentication Required': 511\n} as const\n\nexport const InvertedStatusMap = Object.fromEntries(\n\tObject.entries(StatusMap).map(([k, v]) => [v, k])\n) as {\n\t[K in keyof StatusMap as StatusMap[K]]: K\n}\n\nexport type StatusMap = typeof StatusMap\nexport type InvertedStatusMap = typeof InvertedStatusMap\n\nfunction removeTrailingEquals(digest: string): string {\n\tlet trimmedDigest = digest\n\twhile (trimmedDigest.endsWith('=')) {\n\t\ttrimmedDigest = trimmedDigest.slice(0, -1)\n\t}\n\treturn trimmedDigest\n}\n\nconst encoder = new TextEncoder()\n\nexport const signCookie = async (val: string, secret: string | null) => {\n\tif (typeof val !== 'string')\n\t\tthrow new TypeError('Cookie value must be provided as a string.')\n\n\tif (secret === null) throw new TypeError('Secret key must be provided.')\n\n\tconst secretKey = await crypto.subtle.importKey(\n\t\t'raw',\n\t\tencoder.encode(secret),\n\t\t{ name: 'HMAC', hash: 'SHA-256' },\n\t\tfalse,\n\t\t['sign']\n\t)\n\tconst hmacBuffer = await crypto.subtle.sign(\n\t\t'HMAC',\n\t\tsecretKey,\n\t\tencoder.encode(val)\n\t)\n\n\treturn (\n\t\tval +\n\t\t'.' +\n\t\tremoveTrailingEquals(Buffer.from(hmacBuffer).toString('base64'))\n\t)\n}\n\nexport const unsignCookie = async (input: string, secret: string | null) => {\n\tif (typeof input !== 'string')\n\t\tthrow new TypeError('Signed cookie string must be provided.')\n\n\tif (null === secret) throw new TypeError('Secret key must be provided.')\n\n\tconst tentativeValue = input.slice(0, input.lastIndexOf('.'))\n\tconst expectedInput = await signCookie(tentativeValue, secret)\n\n\treturn expectedInput === input ? tentativeValue : false\n}\n\nexport const traceBackMacro = (\n\textension: unknown,\n\tproperty: Record<string, unknown>,\n\thooks = property\n) => {\n\tif (!extension || typeof extension !== 'object' || !property) return\n\n\tfor (const [key, value] of Object.entries(property)) {\n\t\tif (key in primitiveHookMap || !(key in extension)) continue\n\n\t\tconst v = extension[\n\t\t\tkey as unknown as keyof typeof extension\n\t\t] as BaseMacro[string]\n\n\t\tif (typeof v === 'function') {\n\t\t\tv(value)\n\t\t} else if (typeof v === 'object')\n\t\t\ttraceBackMacro(v as BaseMacro, value as any, hooks)\n\t}\n}\n\nexport const createMacroManager =\n\t({\n\t\tglobalHook,\n\t\tlocalHook\n\t}: {\n\t\tglobalHook: LifeCycleStore\n\t\tlocalHook: LocalHook<any, any, any, any, any, any, any>\n\t}) =>\n\t(stackName: keyof LifeCycleStore) =>\n\t(\n\t\ttype:\n\t\t\t| {\n\t\t\t\t\tinsert?: 'before' | 'after'\n\t\t\t\t\tstack?: 'global' | 'local'\n\t\t\t }\n\t\t\t| MaybeArray<HookContainer>,\n\t\tfn?: MaybeArray<HookContainer>\n\t) => {\n\t\tif (typeof type === 'function')\n\t\t\ttype = {\n\t\t\t\tfn: type\n\t\t\t}\n\n\t\tif ('fn' in type || Array.isArray(type)) {\n\t\t\tif (!localHook[stackName]) localHook[stackName] = []\n\t\t\tif (typeof localHook[stackName] === 'function')\n\t\t\t\tlocalHook[stackName] = [localHook[stackName]]\n\n\t\t\tif (Array.isArray(type))\n\t\t\t\tlocalHook[stackName] = (\n\t\t\t\t\tlocalHook[stackName] as unknown[]\n\t\t\t\t).concat(type) as any\n\t\t\telse localHook[stackName].push(type)\n\n\t\t\treturn\n\t\t}\n\n\t\tconst { insert = 'after', stack = 'local' } = type\n\n\t\tif (typeof fn === 'function') fn = { fn }\n\n\t\tif (stack === 'global') {\n\t\t\tif (!Array.isArray(fn)) {\n\t\t\t\tif (insert === 'before') {\n\t\t\t\t\t;(globalHook[stackName] as any[]).unshift(fn)\n\t\t\t\t} else {\n\t\t\t\t\t;(globalHook[stackName] as any[]).push(fn)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (insert === 'before') {\n\t\t\t\t\tglobalHook[stackName] = fn.concat(\n\t\t\t\t\t\tglobalHook[stackName] as any\n\t\t\t\t\t) as any\n\t\t\t\t} else {\n\t\t\t\t\tglobalHook[stackName] = (\n\t\t\t\t\t\tglobalHook[stackName] as any[]\n\t\t\t\t\t).concat(fn)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!localHook[stackName]) localHook[stackName] = []\n\t\t\tif (typeof localHook[stackName] === 'function')\n\t\t\t\tlocalHook[stackName] = [localHook[stackName]]\n\n\t\t\tif (!Array.isArray(fn)) {\n\t\t\t\tif (insert === 'before') {\n\t\t\t\t\t;(localHook[stackName] as any[]).unshift(fn)\n\t\t\t\t} else {\n\t\t\t\t\t;(localHook[stackName] as any[]).push(fn)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (insert === 'before') {\n\t\t\t\t\tlocalHook[stackName] = fn.concat(localHook[stackName])\n\t\t\t\t} else {\n\t\t\t\t\tlocalHook[stackName] = localHook[stackName].concat(fn)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\nexport const isNumericString = (message: string): boolean => {\n\tif (message.length < 16)\n\t\treturn message.trim().length !== 0 && !Number.isNaN(Number(message))\n\n\t// if 16 digit but less then 9,007,199,254,740,991 then can be parsed\n\tif (message.length === 16) {\n\t\tconst numVal = Number(message)\n\t\tif (numVal.toString() === message)\n\t\t\treturn message.trim().length !== 0 && !Number.isNaN(numVal)\n\t}\n\n\treturn false\n}\n\nexport class PromiseGroup implements PromiseLike<void> {\n\troot: Promise<any> | null = null\n\tpromises: Promise<any>[] = []\n\n\tconstructor(public onError: (error: any) => void = console.error) {}\n\n\t/**\n\t * The number of promises still being awaited.\n\t */\n\tget size() {\n\t\treturn this.promises.length\n\t}\n\n\t/**\n\t * Add a promise to the group.\n\t * @returns The promise that was added.\n\t */\n\tadd<T>(promise: Promise<T>) {\n\t\tthis.promises.push(promise)\n\t\tthis.root ||= this.drain()\n\t\treturn promise\n\t}\n\n\tprivate async drain() {\n\t\twhile (this.promises.length > 0) {\n\t\t\ttry {\n\t\t\t\tawait this.promises[0]\n\t\t\t} catch (error) {\n\t\t\t\tthis.onError(error)\n\t\t\t}\n\t\t\tthis.promises.shift()\n\t\t}\n\t\tthis.root = null\n\t}\n\n\t// Allow the group to be awaited.\n\tthen<TResult1 = void, TResult2 = never>(\n\t\tonfulfilled?:\n\t\t\t| ((value: void) => TResult1 | PromiseLike<TResult1>)\n\t\t\t| undefined\n\t\t\t| null,\n\t\tonrejected?:\n\t\t\t| ((reason: any) => TResult2 | PromiseLike<TResult2>)\n\t\t\t| undefined\n\t\t\t| null\n\t): PromiseLike<TResult1 | TResult2> {\n\t\treturn (this.root ?? Promise.resolve()).then(onfulfilled, onrejected)\n\t}\n}\n\nexport const fnToContainer = (\n\tfn: MaybeArray<Function | HookContainer>\n): MaybeArray<HookContainer> => {\n\tif (!fn) return fn\n\n\tif (!Array.isArray(fn)) {\n\t\tif (typeof fn === 'function') return { fn }\n\t\telse if ('fn' in fn) return fn\n\t}\n\n\tconst fns = <HookContainer[]>[]\n\tfor (const x of fn) {\n\t\tif (typeof x === 'function') fns.push({ fn: x })\n\t\telse if ('fn' in x) fns.push(x)\n\t}\n\n\treturn fns\n}\n\nexport const localHookToLifeCycleStore = (\n\ta: LocalHook<any, any, any, any, any>\n): LifeCycleStore => {\n\treturn {\n\t\t...a,\n\t\tstart: fnToContainer(a?.start),\n\t\trequest: fnToContainer(a?.request),\n\t\tparse: fnToContainer(a?.parse),\n\t\ttransform: fnToContainer(a?.transform),\n\t\tbeforeHandle: fnToContainer(a?.beforeHandle),\n\t\tafterHandle: fnToContainer(a?.afterHandle),\n\t\tonResponse: fnToContainer(a?.onResponse),\n\t\tmapResponse: fnToContainer(a?.mapResponse),\n\t\ttrace: fnToContainer(a?.trace),\n\t\terror: fnToContainer(a?.error),\n\t\tstop: fnToContainer(a?.stop)\n\t}\n}\n\nexport const lifeCycleToFn = (\n\ta: LifeCycleStore\n): LocalHook<any, any, any, any, any, any, any> => {\n\treturn {\n\t\t...a,\n\t\tstart: a.start?.map((x) => x.fn),\n\t\trequest: a.request?.map((x) => x.fn),\n\t\tparse: a.parse?.map((x) => x.fn),\n\t\ttransform: a.transform?.map((x) => x.fn),\n\t\tbeforeHandle: a.beforeHandle?.map((x) => x.fn),\n\t\tafterHandle: a.afterHandle?.map((x) => x.fn),\n\t\tonResponse: a.onResponse?.map((x) => x.fn),\n\t\tmapResponse: a.mapResponse?.map((x) => x.fn),\n\t\ttrace: a.trace?.map((x) => x.fn),\n\t\terror: a.error?.map((x) => x.fn),\n\t\tstop: a.stop?.map((x) => x.fn)\n\t}\n}\n\nexport const cloneInference = (inference: {\n\tevent: Sucrose.Inference\n\ttrace: Sucrose.TraceInference\n}): {\n\tevent: Sucrose.Inference\n\ttrace: Sucrose.TraceInference\n} => ({\n\tevent: {\n\t\tbody: inference.event.body,\n\t\tcookie: inference.event.cookie,\n\t\theaders: inference.event.headers,\n\t\tqueries: [...inference.event.queries],\n\t\tquery: inference.event.query,\n\t\tset: inference.event.set,\n\t\tunknownQueries: inference.event.unknownQueries\n\t},\n\ttrace: {\n\t\trequest: inference.trace.request,\n\t\tparse: inference.trace.parse,\n\t\ttransform: inference.trace.transform,\n\t\thandle: inference.trace.handle,\n\t\tbeforeHandle: inference.trace.beforeHandle,\n\t\tafterHandle: inference.trace.afterHandle,\n\t\terror: inference.trace.error,\n\t\tcontext: inference.trace.context,\n\t\tstore: inference.trace.store,\n\t\tset: inference.trace.set\n\t}\n})\n",
23
23
  "import type { TSchema } from '@sinclair/typebox'\nimport { Value } from '@sinclair/typebox/value'\nimport type { TypeCheck } from '@sinclair/typebox/compiler'\n\nimport { StatusMap, InvertedStatusMap } from './utils'\n\n// ? Cloudflare worker support\nconst env =\n\ttypeof Bun !== 'undefined'\n\t\t? Bun.env\n\t\t: typeof process !== 'undefined'\n\t\t? process?.env\n\t\t: undefined\n\nexport const ERROR_CODE = Symbol('ElysiaErrorCode')\nexport const ELYSIA_RESPONSE = Symbol('ElysiaResponse')\nexport type ELYSIA_RESPONSE = typeof ELYSIA_RESPONSE\n\nexport const isProduction = (env?.NODE_ENV ?? env?.ENV) === 'production'\n\nexport type ElysiaErrors =\n\t| InternalServerError\n\t| NotFoundError\n\t| ParseError\n\t| ValidationError\n\t| InvalidCookieSignature\n\nexport const error = <\n\tconst Code extends number | keyof StatusMap,\n\tconst T = Code extends keyof InvertedStatusMap\n\t\t? InvertedStatusMap[Code]\n\t\t: Code,\n\tconst Status extends Code extends keyof StatusMap\n\t\t? StatusMap[Code]\n\t\t: Code = Code extends keyof StatusMap ? StatusMap[Code] : Code\n>(\n\tcode: Code,\n\tresponse?: T\n): {\n\t[ELYSIA_RESPONSE]: Status\n\tresponse: T\n\t_type: {\n\t\t[ERROR_CODE in Status]: T\n\t}\n} =>\n\t({\n\t\t// @ts-expect-error\n\t\t[ELYSIA_RESPONSE]: StatusMap[code] ?? code,\n\t\tresponse:\n\t\t\tresponse ??\n\t\t\t(code in InvertedStatusMap\n\t\t\t\t? // @ts-expect-error Always correct\n\t\t\t\t InvertedStatusMap[code]\n\t\t\t\t: code),\n\t\t_type: undefined as any\n\t} as const)\n\nexport class InternalServerError extends Error {\n\tcode = 'INTERNAL_SERVER_ERROR'\n\tstatus = 500\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'INTERNAL_SERVER_ERROR')\n\t}\n}\n\nexport class NotFoundError extends Error {\n\tcode = 'NOT_FOUND'\n\tstatus = 404\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'NOT_FOUND')\n\t}\n}\n\nexport class ParseError extends Error {\n\tcode = 'PARSE'\n\tstatus = 400\n\n\tconstructor(message?: string, public body?: unknown) {\n\t\tsuper(message ?? 'PARSE')\n\t}\n}\n\nexport class InvalidCookieSignature extends Error {\n\tcode = 'INVALID_COOKIE_SIGNATURE'\n\tstatus = 400\n\n\tconstructor(public key: string, message?: string) {\n\t\tsuper(message ?? `\"${key}\" has invalid cookie signature`)\n\t}\n}\n\nexport class ValidationError extends Error {\n\tcode = 'VALIDATION'\n\tstatus = 422\n\n\tconstructor(\n\t\tpublic type: string,\n\t\tpublic validator: TSchema | TypeCheck<any>,\n\t\tpublic value: unknown\n\t) {\n\t\t// @ts-expect-error\n\t\tif (typeof value === 'object' && ELYSIA_RESPONSE in value)\n\t\t\t// @ts-expect-error\n\t\t\tvalue = value.response\n\n\t\tconst error = isProduction\n\t\t\t? undefined\n\t\t\t: 'Errors' in validator\n\t\t\t? validator.Errors(value).First()\n\t\t\t: Value.Errors(validator, value).First()\n\n\t\tconst customError = error?.schema.error\n\t\t\t? typeof error.schema.error === 'function'\n\t\t\t\t? error.schema.error(type, validator, value)\n\t\t\t\t: error.schema.error\n\t\t\t: undefined\n\n\t\tconst accessor = error?.path || 'root'\n\t\tlet message = ''\n\n\t\tif (customError) {\n\t\t\tmessage =\n\t\t\t\ttypeof customError === 'object'\n\t\t\t\t\t? JSON.stringify(customError)\n\t\t\t\t\t: customError + ''\n\t\t} else if (isProduction) {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\ttype: 'validation',\n\t\t\t\ton: type,\n\t\t\t\tmessage: error?.message,\n\t\t\t\tfound: value\n\t\t\t})\n\t\t} else {\n\t\t\t// @ts-ignore private field\n\t\t\tconst schema = validator?.schema ?? validator\n\t\t\tconst errors =\n\t\t\t\t'Errors' in validator\n\t\t\t\t\t? [...validator.Errors(value)]\n\t\t\t\t\t: [...Value.Errors(validator, value)]\n\n\t\t\tlet expected\n\n\t\t\ttry {\n\t\t\t\texpected = Value.Create(schema)\n\t\t\t} catch (error) {\n\t\t\t\texpected = {\n\t\t\t\t\ttype: 'Could not create expected value',\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tmessage: error?.message,\n\t\t\t\t\terror\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmessage = JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\ttype: 'validation',\n\t\t\t\t\ton: type,\n\t\t\t\t\tproperty: accessor,\n\t\t\t\t\tmessage: error?.message,\n\t\t\t\t\texpected,\n\t\t\t\t\tfound: value,\n\t\t\t\t\terrors\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2\n\t\t\t)\n\t\t}\n\n\t\tsuper(message)\n\n\t\tObject.setPrototypeOf(this, ValidationError.prototype)\n\t}\n\n\tget all() {\n\t\treturn [...this.validator.Errors(this.value)]\n\t}\n\n\tstatic simplifyModel(validator: TSchema | TypeCheck<any>) {\n\t\t// @ts-ignore\n\t\tconst model = 'schema' in validator ? validator.schema : validator\n\n\t\ttry {\n\t\t\treturn Value.Create(model)\n\t\t} catch {\n\t\t\treturn model\n\t\t}\n\t}\n\n\tget model() {\n\t\treturn ValidationError.simplifyModel(this.validator)\n\t}\n\n\ttoResponse(headers?: Record<string, any>) {\n\t\treturn new Response(this.message, {\n\t\t\tstatus: 400,\n\t\t\theaders: {\n\t\t\t\t...headers,\n\t\t\t\t'content-type': 'application/json'\n\t\t\t}\n\t\t})\n\t}\n}\n",
24
24
  "import type { ServerWebSocket, WebSocketHandler } from 'bun'\n\nimport type { TSchema } from '@sinclair/typebox'\nimport type { TypeCheck } from '@sinclair/typebox/compiler'\n\nimport { ValidationError } from '../error'\nimport type { Context } from '../context'\n\nimport type { SingletonBase, RouteSchema } from '../types'\n\nexport const websocket: WebSocketHandler<any> = {\n\topen(ws) {\n\t\tws.data.open?.(ws)\n\t},\n\tmessage(ws, message) {\n\t\tws.data.message?.(ws, message)\n\t},\n\tdrain(ws) {\n\t\tws.data.drain?.(ws)\n\t},\n\tclose(ws, code, reason) {\n\t\tws.data.close?.(ws, code, reason)\n\t}\n}\n\nexport class ElysiaWS<\n\tWS extends ServerWebSocket<{\n\t\tid?: string\n\t\tvalidator?: TypeCheck<TSchema>\n\t}>,\n\tRoute extends RouteSchema = RouteSchema,\n\tSingleton extends SingletonBase = {\n\t\tdecorator: {}\n\t\tstore: {}\n\t\tderive: {}\n\t\tresolve: {}\n\t}\n> {\n\tvalidator?: TypeCheck<TSchema>\n\n\tconstructor(public raw: WS, public data: Context<Route, Singleton>) {\n\t\tthis.validator = raw.data.validator\n\t\tif (raw.data.id) {\n\t\t\tthis.id = raw.data.id\n\t\t} else {\n\t\t\tconst array = new Uint32Array(1)\n\t\t\tcrypto.getRandomValues(array)\n\t\t\tthis.id = array[0].toString()\n\t\t}\n\t}\n\n\tget id() {\n\t\treturn this.raw.data.id!\n\t}\n\n\tset id(newID: string) {\n\t\tthis.raw.data.id = newID\n\t}\n\n\tget publish() {\n\t\treturn (\n\t\t\ttopic: string,\n\t\t\tdata: Route['response'] = undefined,\n\t\t\tcompress?: boolean\n\t\t) => {\n\t\t\tif (this.validator?.Check(data) === false)\n\t\t\t\tthrow new ValidationError('message', this.validator, data)\n\n\t\t\tif (typeof data === 'object') data = JSON.stringify(data)\n\n\t\t\tthis.raw.publish(topic, data as unknown as string, compress)\n\n\t\t\treturn this\n\t\t}\n\t}\n\n\tget send() {\n\t\treturn (data: Route['response']) => {\n\t\t\tif (this.validator?.Check(data) === false)\n\t\t\t\tthrow new ValidationError('message', this.validator, data)\n\n\t\t\tif (Buffer.isBuffer(data)) {\n\t\t\t\tthis.raw.send(data as unknown as Buffer)\n\n\t\t\t\treturn this\n\t\t\t}\n\n\t\t\tif (typeof data === 'object') data = JSON.stringify(data)\n\n\t\t\tthis.raw.send(data as unknown as string)\n\n\t\t\treturn this\n\t\t}\n\t}\n\n\tget subscribe() {\n\t\treturn (room: string) => {\n\t\t\tthis.raw.subscribe(room)\n\n\t\t\treturn this\n\t\t}\n\t}\n\n\tget unsubscribe() {\n\t\treturn (room: string) => {\n\t\t\tthis.raw.unsubscribe(room)\n\n\t\t\treturn this\n\t\t}\n\t}\n\n\tget cork() {\n\t\treturn (callback: () => this) => {\n\t\t\tthis.raw.cork(callback as any)\n\n\t\t\treturn this\n\t\t}\n\t}\n\n\tget close() {\n\t\treturn () => {\n\t\t\tthis.raw.close()\n\n\t\t\treturn this\n\t\t}\n\t}\n\n\tget terminate() {\n\t\treturn this.raw.terminate.bind(this.raw)\n\t}\n\n\tget isSubscribed() {\n\t\treturn this.raw.isSubscribed.bind(this.raw)\n\t}\n\n\tget remoteAddress() {\n\t\treturn this.raw.remoteAddress\n\t}\n}\n",
25
- "import { type Elysia } from '.'\n\nimport { Value } from '@sinclair/typebox/value'\nimport { TypeCheck } from '@sinclair/typebox/compiler'\nimport type { TAnySchema } from '@sinclair/typebox'\n\nimport { parse as parseQuery } from 'fast-querystring'\n\n// @ts-expect-error\nimport decodeURIComponent from 'fast-decode-uri-component'\n\nimport { getCookieValidator, lifeCycleToFn, signCookie } from './utils'\nimport { ParseError, error } from './error'\n\nimport {\n\tmapEarlyResponse,\n\tmapResponse,\n\tmapCompactResponse,\n\tisNotEmpty\n} from './handler'\nimport {\n\tNotFoundError,\n\tValidationError,\n\tInternalServerError,\n\tERROR_CODE,\n\tELYSIA_RESPONSE\n} from './error'\n\nimport { Sucrose, sucrose } from './sucrose'\nimport { parseCookie, type CookieOptions } from './cookies'\n\nimport type {\n\tComposedHandler,\n\tHandler,\n\tHookContainer,\n\tLifeCycleStore,\n\tSchemaValidator,\n\tTraceEvent\n} from './types'\n\nconst headersHasToJSON = (new Headers() as Headers).toJSON\nconst requestId = { value: 0 }\n\nconst createReport = ({\n\thasTrace,\n\thasTraceSet = false,\n\taddFn,\n\tcondition = {}\n}: {\n\thasTrace: boolean | number\n\thasTraceSet?: boolean\n\taddFn(string: string): void\n\tcondition: Partial<Record<TraceEvent, boolean>>\n}) => {\n\tif (hasTrace) {\n\t\taddFn(`\\nconst reporter = getReporter()\\n`)\n\n\t\treturn (\n\t\t\tevent: TraceEvent,\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\tattribute = '',\n\t\t\t\tunit = 0\n\t\t\t}: {\n\t\t\t\tname?: string\n\t\t\t\tattribute?: string\n\t\t\t\tunit?: number\n\t\t\t} = {}\n\t\t) => {\n\t\t\tconst dotIndex = event.indexOf('.')\n\t\t\tconst isGroup = dotIndex === -1\n\n\t\t\tif (\n\t\t\t\tevent !== 'request' &&\n\t\t\t\tevent !== 'response' &&\n\t\t\t\t!condition[\n\t\t\t\t\t(isGroup\n\t\t\t\t\t\t? event\n\t\t\t\t\t\t: event.slice(0, dotIndex)) as keyof typeof condition\n\t\t\t\t]\n\t\t\t)\n\t\t\t\treturn () => {\n\t\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t\t}\n\n\t\t\tif (isGroup) name ||= event\n\t\t\telse name ||= 'anonymous'\n\n\t\t\taddFn(\n\t\t\t\t'\\n' +\n\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\tid,\n\t\t\t\t\tevent: '${event}',\n\t\t\t\t\ttype: 'begin',\n\t\t\t\t\tname: '${name}',\n\t\t\t\t\ttime: performance.now(),\n\t\t\t\t\t${isGroup ? `unit: ${unit},` : ''}\n\t\t\t\t\t${attribute}\n\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t'\\n'\n\t\t\t)\n\n\t\t\treturn () => {\n\t\t\t\taddFn(\n\t\t\t\t\t'\\n' +\n\t\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tevent: '${event}',\n\t\t\t\t\t\t\ttype: 'end',\n\t\t\t\t\t\t\ttime: performance.now()\n\t\t\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t\t'\\n'\n\t\t\t\t)\n\n\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t}\n\t\t}\n\t} else {\n\t\treturn () => () => {}\n\t}\n}\n\nexport const hasReturn = (fnLiteral: string) => {\n\tconst parenthesisEnd = fnLiteral.indexOf(')')\n\n\t// Is direct arrow function return eg. () => 1\n\tif (\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 2) === 61 &&\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 5) !== 123\n\t) {\n\t\treturn true\n\t}\n\n\treturn fnLiteral.includes('return')\n}\n\nconst composeValidationFactory = (\n\thasErrorHandler: boolean,\n\t{\n\t\tinjectResponse = '',\n\t\tnormalize = false\n\t}: {\n\t\tinjectResponse?: string\n\t\tnormalize?: boolean\n\t} = {}\n) => ({\n\tcomposeValidation: (type: string, value = `c.${type}`) =>\n\t\thasErrorHandler\n\t\t\t? `c.set.status = 422; throw new ValidationError('${type}', ${type}, ${value})`\n\t\t\t: `c.set.status = 422; return new ValidationError('${type}', ${type}, ${value}).toResponse(c.set.headers)`,\n\tcomposeResponseValidation: (name = 'r') => {\n\t\tconst returnError = hasErrorHandler\n\t\t\t? `throw new ValidationError('response', response[c.set.status], ${name})`\n\t\t\t: `return new ValidationError('response', response[c.set.status], ${name}).toResponse(c.set.headers)`\n\n\t\tlet code = '\\n' + injectResponse + '\\n'\n\n\t\tcode += `let er\n\t\t\n\t\tif(${name} && typeof ${name} === \"object\" && ELYSIA_RESPONSE in ${name})\n\t\t\ter = ${name}[ELYSIA_RESPONSE]\\n`\n\n\t\tif (normalize)\n\t\t\tcode += `\n\t\t\tif(!er && response[c.set.status]?.Clean)\n\t\t\t\t${name} = response[c.set.status]?.Clean(${name})\n\t\t\telse if(response[er]?.Clean)\n\t\t\t\t${name}.response = response[er]?.Clean(${name}.response)`\n\n\t\tcode += `\n\t\t\tif(er) {\n\t\t\t\tif(!(${name} instanceof Response) && response[er]?.Check(${name}.response) === false) {\n\t\t\t\t\tif(!(response instanceof Error)) {\n\t\t\t\t\t\tc.set.status = ${name}[ELYSIA_RESPONSE]\n\n\t\t\t\t\t\t${returnError}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if(!(${name} instanceof Response) && response[c.set.status]?.Check(${name}) === false) {\n\t\t\t\tif(!(response instanceof Error))\n\t\t\t\t\t${returnError}\n\t\t\t}\\n`\n\n\t\treturn code\n\t}\n})\n\nconst KindSymbol = Symbol.for('TypeBox.Kind')\n\nexport const hasType = (type: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (KindSymbol in schema && schema[KindSymbol] === type) return true\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasType(type, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasType(type, property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tif (KindSymbol in property && property[KindSymbol] === type)\n\t\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tschema.properties &&\n\t\tKindSymbol in schema.properties &&\n\t\tschema.properties[KindSymbol] === type\n\t)\n}\n\nexport const hasProperty = (expectedProperty: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\n\t\tif (!properties) return false\n\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (expectedProperty in property) return true\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasProperty(expectedProperty, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++) {\n\t\t\t\t\tif (hasProperty(expectedProperty, property.anyOf[i]))\n\t\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn expectedProperty in schema\n}\n\nconst TransformSymbol = Symbol.for('TypeBox.Transform')\n\nexport const hasTransform = (schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object' && schema.properties) {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasTransform(property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasTransform(property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tconst hasTransformSymbol = TransformSymbol in property\n\t\t\tif (hasTransformSymbol) return true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tTransformSymbol in schema ||\n\t\t(schema.properties && TransformSymbol in schema.properties)\n\t)\n}\n\n/**\n * This function will return the type of unioned if all unioned type is the same.\n * It's intent to use for content-type mapping only\n *\n * ```ts\n * t.Union([\n * t.Object({\n * password: t.String()\n * }),\n * t.Object({\n * token: t.String()\n * })\n * ])\n * ```\n */\nconst getUnionedType = (validator: TypeCheck<any> | undefined) => {\n\tif (!validator) return\n\n\t// @ts-ignore\n\tconst schema = validator?.schema\n\n\tif (schema && 'anyOf' in schema) {\n\t\tlet foundDifference = false\n\t\tconst type: string = schema.anyOf[0].type\n\n\t\tfor (const validator of schema.anyOf as { type: string }[]) {\n\t\t\tif (validator.type !== type) {\n\t\t\t\tfoundDifference = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (!foundDifference) return type\n\t}\n\n\t// @ts-ignore\n\treturn validator.schema?.type\n}\n\nconst matchFnReturn = /(?:return|=>) \\S+\\(/g\n\nexport const isAsync = (v: Function | HookContainer) => {\n\tconst fn = 'fn' in v ? v.fn : v\n\n\tif (fn.constructor.name === 'AsyncFunction') return true\n\n\tconst literal = fn.toString()\n\tif (literal.includes('=> response.clone(')) return false\n\n\treturn !!literal.match(matchFnReturn)\n}\n\nexport const composeHandler = ({\n\tapp,\n\tpath,\n\tmethod,\n\tlocalHook,\n\thooks,\n\tvalidator,\n\thandler,\n\tallowMeta = false,\n\tappInference: { event: eventInference, trace: traceInference }\n}: {\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n\tpath: string\n\tmethod: string\n\thooks: LifeCycleStore\n\tlocalHook: LifeCycleStore\n\tvalidator: SchemaValidator\n\thandler: unknown | Handler<any, any>\n\tallowMeta?: boolean\n\tappInference: {\n\t\tevent: Sucrose.Inference\n\t\ttrace: Sucrose.TraceInference\n\t}\n}): ComposedHandler => {\n\tconst isHandleFn = typeof handler === 'function'\n\n\tif (!isHandleFn)\n\t\thandler = mapResponse(handler, {\n\t\t\t// @ts-expect-error private property\n\t\t\theaders: app.setHeaders ?? {}\n\t\t})\n\n\tconst hasErrorHandler =\n\t\t(app.config.forceErrorEncapsulation &&\n\t\t\t(isHandleFn ||\n\t\t\t\thooks.afterHandle.length > 0 ||\n\t\t\t\thooks.beforeHandle.length > 0 ||\n\t\t\t\thooks.transform.length > 0)) ||\n\t\thooks.error.length > 0 ||\n\t\tapp.event.error.length > 0 ||\n\t\ttypeof Bun === 'undefined' ||\n\t\thooks.onResponse.length > 0 ||\n\t\thooks.onResponse.length > 0 ||\n\t\t!!hooks.trace.length\n\n\tconst handle = isHandleFn ? `handler(c)` : `handler`\n\tconst handleResponse = hooks.onResponse.length\n\t\t? `\\n;(async () => {${hooks.onResponse\n\t\t\t\t.map((_, i) => `await res${i}(c)`)\n\t\t\t\t.join(';')}})();\\n`\n\t\t: ''\n\n\tconst traceConditions: Record<\n\t\tExclude<TraceEvent, `${string}.unit` | 'request' | 'response' | 'exit'>,\n\t\tboolean\n\t> = traceInference\n\n\tconst hasTrace = hooks.trace.length > 0\n\tlet fnLiteral = ''\n\n\tconst inference = sucrose(\n\t\tObject.assign(localHook, {\n\t\t\thandler: handler as any\n\t\t}),\n\t\teventInference\n\t)\n\n\tconst hasQuery = inference.query || !!validator.query\n\n\tconst hasBody =\n\t\tmethod !== '$INTERNALWS' &&\n\t\tmethod !== 'GET' &&\n\t\tmethod !== 'HEAD' &&\n\t\thooks.type !== 'none' &&\n\t\t(inference.body || !!validator.body)\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\tconst hasDefaultHeaders =\n\t\tdefaultHeaders && !!Object.keys(defaultHeaders).length\n\n\t// ? defaultHeaders doesn't imply that user will use headers in handler\n\tconst hasHeaders = inference.headers || validator.headers\n\tconst hasCookie = inference.cookie || !!validator.cookie\n\n\tconst cookieValidator = hasCookie\n\t\t? getCookieValidator({\n\t\t\t\tvalidator: validator.cookie as any,\n\t\t\t\tdefaultConfig: app.config.cookie,\n\t\t\t\tdynamic: !!app.config.aot,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tconfig: validator.cookie?.config ?? {},\n\t\t\t\t// @ts-expect-error\n\t\t\t\tmodels: app.definitions.type\n\t\t })\n\t\t: undefined\n\n\t// @ts-ignore private property\n\tconst cookieMeta = cookieValidator?.config as {\n\t\tsecrets?: string | string[]\n\t\tsign: string[] | true\n\t\tproperties: { [x: string]: Object }\n\t}\n\n\tlet encodeCookie = ''\n\n\tif (cookieMeta?.sign) {\n\t\tif (!cookieMeta.secrets)\n\t\t\tthrow new Error(\n\t\t\t\t`t.Cookie required secret which is not set in (${method}) ${path}.`\n\t\t\t)\n\n\t\tconst secret = !cookieMeta.secrets\n\t\t\t? undefined\n\t\t\t: typeof cookieMeta.secrets === 'string'\n\t\t\t? cookieMeta.secrets\n\t\t\t: cookieMeta.secrets[0]\n\n\t\tencodeCookie += `const _setCookie = c.set.cookie\n\t\tif(_setCookie) {`\n\n\t\tif (cookieMeta.sign === true) {\n\t\t\tencodeCookie += `for(const [key, cookie] of Object.entries(_setCookie)) {\n\t\t\t\tc.set.cookie[key].value = await signCookie(cookie.value, '${secret}')\n\t\t\t}`\n\t\t} else\n\t\t\tfor (const name of cookieMeta.sign) {\n\t\t\t\tencodeCookie += `if(_setCookie['${name}']?.value) { c.set.cookie['${name}'].value = await signCookie(_setCookie['${name}'].value, '${secret}') }\\n`\n\t\t\t}\n\n\t\tencodeCookie += '}\\n'\n\t}\n\n\tconst normalize = app.config.normalize\n\n\tconst { composeValidation, composeResponseValidation } =\n\t\tcomposeValidationFactory(hasErrorHandler, {\n\t\t\tnormalize\n\t\t})\n\n\tif (hasHeaders) {\n\t\t// This function is Bun specific\n\t\t// @ts-ignore\n\t\tfnLiteral += headersHasToJSON\n\t\t\t? `c.headers = c.request.headers.toJSON()\\n`\n\t\t\t: `c.headers = {}\n for (const [key, value] of c.request.headers.entries())\n\t\t\t\t\tc.headers[key] = value\n\t\t\t\t`\n\t}\n\n\tif (hasCookie) {\n\t\tconst get = (name: keyof CookieOptions, defaultValue?: unknown) => {\n\t\t\t// @ts-ignore\n\t\t\tconst value = cookieMeta?.[name] ?? defaultValue\n\t\t\tif (!value)\n\t\t\t\treturn typeof defaultValue === 'string'\n\t\t\t\t\t? `${name}: \"${defaultValue}\",`\n\t\t\t\t\t: `${name}: ${defaultValue},`\n\n\t\t\tif (typeof value === 'string') return `${name}: '${value}',`\n\t\t\tif (value instanceof Date)\n\t\t\t\treturn `${name}: new Date(${value.getTime()}),`\n\n\t\t\treturn `${name}: ${value},`\n\t\t}\n\n\t\tconst options = cookieMeta\n\t\t\t? `{\n\t\t\tsecrets: ${\n\t\t\t\tcookieMeta.secrets !== undefined\n\t\t\t\t\t? typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t\t? `'${cookieMeta.secrets}'`\n\t\t\t\t\t\t: '[' +\n\t\t\t\t\t\t cookieMeta.secrets.reduce(\n\t\t\t\t\t\t\t\t(a, b) => a + `'${b}',`,\n\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t ) +\n\t\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\tsign: ${\n\t\t\t\tcookieMeta.sign === true\n\t\t\t\t\t? true\n\t\t\t\t\t: cookieMeta.sign !== undefined\n\t\t\t\t\t? '[' +\n\t\t\t\t\t cookieMeta.sign.reduce((a, b) => a + `'${b}',`, '') +\n\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\t${get('domain')}\n\t\t\t${get('expires')}\n\t\t\t${get('httpOnly')}\n\t\t\t${get('maxAge')}\n\t\t\t${get('path', '/')}\n\t\t\t${get('priority')}\n\t\t\t${get('sameSite')}\n\t\t\t${get('secure')}\n\t\t}`\n\t\t\t: 'undefined'\n\n\t\tif (hasHeaders)\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${options})\\n`\n\t\telse\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${options})\\n`\n\t}\n\n\tif (hasQuery) {\n\t\tlet destructured = [] as string[]\n\n\t\t// @ts-ignore\n\t\tif (validator.query && validator.query.schema.type === 'object') {\n\t\t\t// @ts-ignore\n\t\t\tdestructured = Object.keys(validator.query.schema.properties)\n\t\t} else\n\t\t\tfor (const query of inference.queries)\n\t\t\t\tif (destructured.indexOf(query) === -1) destructured.push(query)\n\n\t\tif (\n\t\t\tapp.config.forceDynamicQuery === true ||\n\t\t\tinference.unknownQueries === true ||\n\t\t\t!destructured.length\n\t\t) {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tc.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\\\+/g, ' '))\n\n\t\t\t\tfor(const key of Object.keys(c.query))\n\t\t\t\t\tc.query[key] = decodeURIComponent(c.query[key])\n\t\t\t} else c.query = {}`\n\t\t} else {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tlet url = c.request.url.slice(c.qi).replace(/\\\\+/g, ' ')\n\n\t\t\t\t${destructured\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(name, index) => `\n\t\t\t\t\t\t${index === 0 ? 'let' : ''} memory = url.indexOf('&${name}=')\n\t\t\t\t\t\tif(memory === -1) memory = url.indexOf('?${name}=')\n\t\t\t\t\t\tlet a${index}\n\n\t\t\t\t\t\tif(memory !== -1) {\n\t\t\t\t\t\t\tconst start = memory + ${name.length + 2}\n\t\t\t\t\t\t\tmemory = url.indexOf('&', start)\n\n\t\t\t\t\t\t\tif(memory === -1) a${index} = decodeURIComponent(url.slice(start))\n\t\t\t\t\t\t\telse a${index} = decodeURIComponent(url.slice(start, memory))\n\t\t\t\t\t\t}`\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n')}\n\n\t\t\t\tc.query = {\n\t\t\t\t\t${destructured.map((name, index) => `'${name}': a${index}`).join(', ')}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tc.query = {}\n\t\t\t}`\n\t\t}\n\t}\n\n\tconst hasTraceSet = traceInference.set\n\tconst hasSet =\n\t\tinference.cookie ||\n\t\tinference.set ||\n\t\thasTraceSet ||\n\t\thasHeaders ||\n\t\t(isHandleFn && hasDefaultHeaders)\n\n\tif (hasTrace) fnLiteral += '\\nconst id = c.$$requestId\\n'\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet,\n\t\tcondition: traceConditions,\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tfnLiteral += hasErrorHandler ? '\\n try {\\n' : ''\n\n\tif (hasTraceSet) {\n\t\tfnLiteral += `\\nconst traceDone = Promise.all([`\n\t\tfor (let i = 0; i < hooks.trace.length; i++) {\n\t\t\tfnLiteral += `new Promise(r => { reporter.once(\\`res\\${id}.${i}\\`, r) }),`\n\t\t}\n\t\tfnLiteral += `])\\n`\n\t}\n\n\tconst isAsyncHandler = typeof handler === 'function' && isAsync(handler)\n\n\tconst maybeAsync =\n\t\thasCookie ||\n\t\thasBody ||\n\t\thasTraceSet ||\n\t\tisAsyncHandler ||\n\t\t!!hooks.mapResponse.length ||\n\t\thooks.parse.length > 0 ||\n\t\thooks.afterHandle.some(isAsync) ||\n\t\thooks.beforeHandle.some(isAsync) ||\n\t\thooks.transform.some(isAsync)\n\n\tconst endParse = report('parse', {\n\t\tunit: hooks.parse.length\n\t})\n\n\tif (hasBody) {\n\t\tconst type = getUnionedType(validator?.body)\n\n\t\tif (hooks.type && !Array.isArray(hooks.type)) {\n\t\t\tif (hooks.type) {\n\t\t\t\tswitch (hooks.type) {\n\t\t\t\t\tcase 'json':\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\tif (hasErrorHandler)\n\t\t\t\t\t\t\tfnLiteral += `const tempBody = await c.request.text()\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t\t}`\n\t\t\t\t\t\telse fnLiteral += `c.body = await c.request.json()`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text':\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.text()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'urlencoded':\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tfnLiteral += `c.body = parseQuery(await c.request.text())\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'arrayBuffer':\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.arrayBuffer()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'formdata':\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tfnLiteral += `c.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (hooks.parse.length) fnLiteral += '}}'\n\t\t} else {\n\t\t\tconst getAotParser = () => {\n\t\t\t\tif (hooks.parse.length && type && !Array.isArray(hooks.type)) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst schema = validator?.body?.schema\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof schema === 'object' &&\n\t\t\t\t\t\t(hasType('File', schema) || hasType('Files', schema))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn `c.body = {}\n\n\t\t\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t\t\t}`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst aotParse = getAotParser()\n\n\t\t\tif (aotParse) fnLiteral += aotParse\n\t\t\telse {\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t\tfnLiteral += hasHeaders\n\t\t\t\t\t? `let contentType = c.headers['content-type']`\n\t\t\t\t\t: `let contentType = c.request.headers.get('content-type')`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tif (contentType) {\n\t\t\t\t\tconst index = contentType.indexOf(';')\n\t\t\t\t\tif (index !== -1) contentType = contentType.substring(0, index)\\n`\n\n\t\t\t\tif (hooks.parse.length) {\n\t\t\t\t\tfnLiteral += `let used = false\\n`\n\n\t\t\t\t\tconst endReport = report('parse', {\n\t\t\t\t\t\tunit: hooks.parse.length\n\t\t\t\t\t})\n\n\t\t\t\t\tfor (let i = 0; i < hooks.parse.length; i++) {\n\t\t\t\t\t\tconst endUnit = report('parse.unit', {\n\t\t\t\t\t\t\tname: hooks.parse[i].fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tconst name = `bo${i}`\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `if(!used) {\\n`\n\n\t\t\t\t\t\tfnLiteral += `let ${name} = parse[${i}](c, contentType)\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} instanceof Promise) ${name} = await ${name}\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} !== undefined) { c.body = ${name}; used = true }\\n`\n\n\t\t\t\t\t\tendUnit()\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `}`\n\t\t\t\t\t}\n\n\t\t\t\t\tendReport()\n\t\t\t\t}\n\n\t\t\t\tif (hooks.parse.length) fnLiteral += `if (!used)`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tswitch (contentType) {\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t${\n\t\t\t\t\t\t\thasErrorHandler\n\t\t\t\t\t\t\t\t? `\n\t\t\t\t\t\tconst tempBody = await c.request.text()\n\t\t\t\t\t\t\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t: `c.body = await c.request.json()\\n`\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tc.body = await c.request.text()\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tc.body = parseQuery(await c.request.text())\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tc.body = await c.request.arrayBuffer();\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tc.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\\n`\n\n\t\t\t\tfnLiteral += '}\\n'\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += '\\n'\n\t}\n\n\tendParse()\n\n\tif (hooks?.transform) {\n\t\tconst endTransform = report('transform', {\n\t\t\tunit: hooks.transform.length\n\t\t})\n\n\t\tif (hooks.transform.length) fnLiteral += '\\nlet transformed\\n'\n\n\t\tfor (let i = 0; i < hooks.transform.length; i++) {\n\t\t\tconst transform = hooks.transform[i]\n\n\t\t\tconst endUnit = report('transform.unit', {\n\t\t\t\tname: transform.fn.name\n\t\t\t})\n\n\t\t\tfnLiteral += isAsync(transform)\n\t\t\t\t? `transformed = await transform[${i}](c)\\n`\n\t\t\t\t: `transformed = transform[${i}](c)\\n`\n\n\t\t\tfnLiteral += `if(transformed?.[ELYSIA_RESPONSE])\n\t\t\t\tthrow transformed\n\t\t\telse\n\t\t\t\tObject.assign(c, transformed)\\n`\n\n\t\t\tendUnit()\n\t\t}\n\n\t\tendTransform()\n\t}\n\n\tif (validator) {\n\t\tfnLiteral += '\\n'\n\n\t\tif (validator.headers) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.headers.params))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.headers.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.headers['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(headers.Check(c.headers) === false) {\n\t\t\t\t${composeValidation('headers')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.headers.schema))\n\t\t\t\tfnLiteral += `\\nc.headers = headers.Decode(c.headers)\\n`\n\t\t}\n\n\t\tif (validator.params) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.params.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.params.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.params['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(params.Check(c.params) === false) {\n\t\t\t\t${composeValidation('params')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.params.schema))\n\t\t\t\tfnLiteral += `\\nc.params = params.Decode(c.params)\\n`\n\t\t}\n\n\t\tif (validator.query) {\n\t\t\tif (normalize) fnLiteral += 'c.query = query.Clean(c.query);\\n'\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.query.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.query.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed) fnLiteral += `c.query['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(query.Check(c.query) === false) {\n\t\t\t\t${composeValidation('query')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.query.schema))\n\t\t\t\t// Decode doesn't work with Object.create(null)\n\t\t\t\tfnLiteral += `\\nc.query = query.Decode(Object.assign({}, c.query))\\n`\n\t\t}\n\n\t\tif (validator.body) {\n\t\t\tif (normalize) fnLiteral += 'c.body = body.Clean(c.body);\\n'\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.body.schema))\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n \t\t\t\tc.body = Object.assign(${JSON.stringify(\n\t\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tvalidator.body.schema,\n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t) ?? {}\n\t\t\t\t\t)}, c.body)\n\n \t\t\t\tif(body.Check(c.query) === false) {\n \t\t\t\t${composeValidation('body')}\n \t\t\t}\n }`\n\t\t\telse\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n\t\t\t${composeValidation('body')}\n\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.body.schema))\n\t\t\t\tfnLiteral += `\\nc.body = body.Decode(c.body)\\n`\n\t\t}\n\n\t\t// @ts-ignore\n\t\tif (isNotEmpty(cookieValidator?.schema.properties ?? {})) {\n\t\t\tfnLiteral += `const cookieValue = {}\n \t\t\tfor(const [key, value] of Object.entries(c.cookie))\n \t\t\t\tcookieValue[key] = value.value\\n`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', cookieValidator.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tcookieValidator.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tfnLiteral += `cookieValue['${key}'] = ${\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: value\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(cookie.Check(cookieValue) === false) {\n\t\t\t\t${composeValidation('cookie', 'cookieValue')}\n\t\t\t}`\n\n\t\t\t// // @ts-ignore\n\t\t\t// if (hasTransform(validator.cookie.schema))\n\t\t\t// \tfnLiteral += `\\nc.cookie = params.Decode(c.cookie)\\n`\n\t\t}\n\t}\n\n\tif (hooks?.beforeHandle) {\n\t\tconst endBeforeHandle = report('beforeHandle', {\n\t\t\tunit: hooks.beforeHandle.length\n\t\t})\n\n\t\tlet hasResolve = false\n\n\t\tfor (let i = 0; i < hooks.beforeHandle.length; i++) {\n\t\t\tconst beforeHandle = hooks.beforeHandle[i]\n\n\t\t\tconst endUnit = report('beforeHandle.unit', {\n\t\t\t\tname: beforeHandle.fn.name\n\t\t\t})\n\n\t\t\tconst returning = hasReturn(beforeHandle.fn.toString())\n\n\t\t\tconst isResolver = beforeHandle.subType === 'resolve'\n\n\t\t\tif (isResolver) {\n\t\t\t\tif (!hasResolve) {\n\t\t\t\t\thasResolve = true\n\t\t\t\t\tfnLiteral += '\\nlet resolved\\n'\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `resolved = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `resolved = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tfnLiteral += `if(resolved[ELYSIA_RESPONSE])\n\t\t\t\t\t\tthrow resolved\n\t\t\t\t\telse\n\t\t\t\t\t\tObject.assign(c, resolved)\\n`\n\t\t\t} else if (!returning) {\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += `Object.assign(c, be);`\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `be = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `be = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(be !== undefined) {\\n`\n\t\t\t\tendBeforeHandle()\n\t\t\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\t\t\tunit: hooks.transform.length\n\t\t\t\t})\n\t\t\t\tif (hooks.afterHandle) {\n\t\t\t\t\treport('handle', {\n\t\t\t\t\t\tname: isHandleFn\n\t\t\t\t\t\t\t? (handler as Function).name\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t})()\n\n\t\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\t\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\t\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\t\t\t\tname: hook.fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tfnLiteral += `c.response = be\\n`\n\n\t\t\t\t\t\tif (!returning) {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `await afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t\t\t: `afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\t\t\t\tfnLiteral += `if(af !== undefined) { c.response = be = af }\\n`\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tendUnit()\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tendAfterHandle()\n\n\t\t\t\tif (validator.response)\n\t\t\t\t\tfnLiteral += composeResponseValidation('be')\n\n\t\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\t\tfnLiteral += `c.response = be`\n\n\t\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\t\t\t\tif(mr !== undefined) c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += encodeCookie\n\t\t\t\tfnLiteral += `return mapEarlyResponse(be, c.set, c.request)}\\n`\n\t\t\t}\n\t\t}\n\n\t\tendBeforeHandle()\n\t}\n\n\tif (hooks?.afterHandle.length) {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (hooks.afterHandle.length)\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = c.response = await ${handle};\\n`\n\t\t\t\t: `let r = c.response = ${handle};\\n`\n\t\telse\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\tendHandle()\n\n\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\tunit: hooks.afterHandle.length\n\t\t})\n\n\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\tname: hook.fn.name\n\t\t\t})\n\n\t\t\tif (!returning) {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tif (validator.response) {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += composeResponseValidation('af')\n\n\t\t\t\t\tfnLiteral += `c.response = af }`\n\t\t\t\t} else {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += `c.response = af}\\n`\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tendAfterHandle()\n\n\t\tfnLiteral += `r = c.response\\n`\n\n\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\tfnLiteral += encodeCookie\n\n\t\tif (hooks.mapResponse.length) {\n\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\tfnLiteral += `\\nmr = onMapResponse[${i}](c)\n\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\tif(mr !== undefined) c.response = mr\\n`\n\t\t\t}\n\t\t}\n\n\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t} else {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (validator.response || hooks.mapResponse.length) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) { \n\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else if (traceConditions.handle || hasCookie) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else {\n\t\t\tendHandle()\n\n\t\t\tconst handled = isAsyncHandler ? `await ${handle}` : handle\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(${handled}, c.set, c.request)\\n`\n\t\t\telse\n\t\t\t\tfnLiteral += `return mapCompactResponse(${handled}, c.request)\\n`\n\t\t}\n\t}\n\n\tif (hasErrorHandler || handleResponse) {\n\t\tfnLiteral += `\\n} catch(error) {`\n\t\tif (!maybeAsync) fnLiteral += `return (async () => {`\n\n\t\tfnLiteral += `const set = c.set\\nif (!set.status || set.status < 300) set.status = error?.status || 500\\n`\n\n\t\tconst endError = report('error', {\n\t\t\tunit: hooks.error.length\n\t\t})\n\n\t\tif (hooks.error.length) {\n\t\t\tfnLiteral += `\n\t\t\t\tc.error = error\n\t\t\t\tc.code = error.code ?? error[ERROR_CODE] ?? \"UNKNOWN\"\n\t\t\t`\n\n\t\t\tfor (let i = 0; i < hooks.error.length; i++) {\n\t\t\t\tconst name = `er${i}`\n\t\t\t\tconst endUnit = report('error.unit', {\n\t\t\t\t\tname: hooks.error[i].fn.name\n\t\t\t\t})\n\n\t\t\t\tfnLiteral += `\\nlet ${name} = handleErrors[${i}](c)\\n`\n\n\t\t\t\tif (isAsync(hooks.error[i]))\n\t\t\t\t\tfnLiteral += `if (${name} instanceof Promise) ${name} = await ${name}\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `${name} = mapEarlyResponse(${name}, set, c.request)\\n`\n\t\t\t\tfnLiteral += `if (${name}) {`\n\t\t\t\tfnLiteral += `return ${name} }\\n`\n\t\t\t}\n\t\t}\n\n\t\tendError()\n\n\t\tfnLiteral += `return handleError(c, error, true)\\n\\n`\n\n\t\tif (!maybeAsync) fnLiteral += '})()'\n\n\t\tfnLiteral += '}'\n\n\t\tif (handleResponse || hasTrace) {\n\t\t\tfnLiteral += ` finally { `\n\n\t\t\tconst endResponse = report('response', {\n\t\t\t\tunit: hooks.onResponse.length\n\t\t\t})\n\n\t\t\tfnLiteral += handleResponse\n\n\t\t\tendResponse()\n\n\t\t\tfnLiteral += `}`\n\t\t}\n\t}\n\n\tfnLiteral = `const {\n\t\thandler,\n\t\thandleError,\n\t\thooks: {\n\t\t\ttransform,\n\t\t\tresolve,\n\t\t\tbeforeHandle,\n\t\t\tafterHandle,\n\t\t\tmapResponse: onMapResponse,\n\t\t\tparse,\n\t\t\terror: handleErrors,\n\t\t\tonResponse\n\t\t},\n\t\tvalidator: {\n\t\t\tbody,\n\t\t\theaders,\n\t\t\tparams,\n\t\t\tquery,\n\t\t\tresponse,\n\t\t\tcookie\n\t\t},\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema,\n\t\tdefinitions,\n\t\tERROR_CODE,\n\t\tgetReporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t} = hooks\n\n\t${\n\t\thooks.onResponse.length\n\t\t\t? `const ${hooks.onResponse\n\t\t\t\t\t.map((x, i) => `res${i} = onResponse[${i}]`)\n\t\t\t\t\t.join(',')}`\n\t\t\t: ''\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function handle(c) {\n\t\t${hooks.beforeHandle.length ? 'let be' : ''}\n\t\t${hooks.afterHandle.length ? 'let af' : ''}\n\t\t${hooks.mapResponse.length ? 'let mr' : ''}\n\n\t\t${allowMeta ? 'c.schema = schema; c.defs = definitions' : ''}\n\t\t${fnLiteral}\n\t}`\n\n\tconst createHandler = Function('hooks', fnLiteral)\n\n\treturn createHandler({\n\t\thandler,\n\t\thooks: lifeCycleToFn(hooks),\n\t\tvalidator,\n\t\t// @ts-expect-error\n\t\thandleError: app.handleError,\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema: app.router.history,\n\t\t// @ts-expect-error\n\t\tdefinitions: app.definitions.type,\n\t\tERROR_CODE,\n\t\t// @ts-expect-error\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const composeGeneralHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tconst inference = {\n\t\tevent: {\n\t\t\t// @ts-expect-error\n\t\t\t...app.inference.event,\n\t\t\t// @ts-expect-error\n\t\t\tqueries: [...app.inference.event.queries]\n\t\t},\n\t\t// @ts-expect-error\n\t\ttrace: { ...app.inference.trace }\n\t}\n\n\tlet decoratorsLiteral = ''\n\tlet fnLiteral = ''\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\n\t// @ts-ignore\n\tfor (const key of Object.keys(app.singleton.decorator))\n\t\tdecoratorsLiteral += `,${key}: app.singleton.decorator.${key}`\n\n\tconst router = app.router\n\tconst hasTrace = app.event.trace.length > 0\n\n\tlet findDynamicRoute = `\n\tconst route = router.find(request.method, path) ${\n\t\trouter.http.root.ALL ? '?? router.find(\"ALL\", path)' : ''\n\t}\n\n\tif (route === null)\n\t\treturn ${\n\t\t\tapp.event.error.length\n\t\t\t\t? `app.handleError(ctx, notFound)`\n\t\t\t\t: app.event.request.length\n\t\t\t\t? `new Response(error404Message, {\n\t\t\t\t\tstatus: ctx.set.status === 200 ? 404 : ctx.set.status,\n\t\t\t\t\theaders: ctx.set.headers\n\t\t\t\t})`\n\t\t\t\t: `error404.clone()`\n\t\t}\n\n\tctx.params = route.params\\n`\n\n\tconst shouldPrecompile =\n\t\tapp.config.precompile === true ||\n\t\t(typeof app.config.precompile === 'object' &&\n\t\t\tapp.config.precompile.compose === true)\n\n\tif (!shouldPrecompile)\n\t\tfindDynamicRoute += `\n\t\t\tif(route.store.composed)\n\t\t\t\treturn route.store.composed(ctx)\n\n\t\t\tif(route.store.compose)\n\t\t\t\treturn (route.store.compose())(ctx)`\n\telse findDynamicRoute += `return route.store(ctx)`\n\n\tfindDynamicRoute += '\\n'\n\n\tlet switchMap = ``\n\tfor (const [path, { code, all }] of Object.entries(router.static.http.map))\n\t\tswitchMap += `case '${path}':\\nswitch(request.method) {\\n${code}\\n${\n\t\t\tall ?? `default: break map`\n\t\t}}\\n\\n`\n\n\tconst maybeAsync = app.event.request.some(isAsync)\n\n\tconst init = `\\n\n\tconst url = request.url\n\tconst s = url.indexOf('/', 11)\n\tconst qi = url.indexOf('?', s + 1)\n\tlet path\n\tif(qi === -1)\n\t\tpath = url.substring(s)\n\telse \n\t\tpath = url.substring(s, qi)\\n`\n\n\tfnLiteral += `const {\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\trequestId,\n\t\tgetReporter,\n\t\thandleError,\n\t\terror\n\t} = data\n\n\tconst store = app.singleton.store\n\tconst staticRouter = app.router.static.http\n\tconst wsRouter = app.router.ws\n\tconst router = app.router.http\n\n\tconst notFound = new NotFoundError()\n\n\t${\n\t\tapp.event.request.length\n\t\t\t? `const onRequest = app.event.request.map(x => x.fn)`\n\t\t\t: ''\n\t}\n\t${router.static.http.variables}\n\t${\n\t\tapp.event.error.length\n\t\t\t? ''\n\t\t\t: `\n\tconst error404Message = notFound.message.toString()\n\tconst error404 = new Response(error404Message, { status: 404 });\n\t`\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function map(request) {\\n`\n\n\tif (app.event.request.length) fnLiteral += `let re`\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet: inference.trace.set,\n\t\tcondition: {\n\t\t\trequest: inference.trace.request\n\t\t},\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tif (app.event.request.length) {\n\t\tfnLiteral += `\n\t\t\t${hasTrace ? 'const id = +requestId.value++' : ''}\n\n\t\t\tconst ctx = {\n\t\t\t\trequest,\n\t\t\t\tstore,\n\t\t\t\tset: {\n\t\t\t\t\theaders: ${\n\t\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t\t: '{}'\n\t\t\t\t\t},\n\t\t\t\t\tstatus: 200\n\t\t\t\t},\n\t\t\t\terror\n\t\t\t\t${hasTrace ? ',$$requestId: +id' : ''}\n\t\t\t\t${decoratorsLiteral}\n\t\t\t}\n\t\t`\n\n\t\tconst endReport = report('request', {\n\t\t\tattribute: 'ctx',\n\t\t\tunit: app.event.request.length\n\t\t})\n\n\t\tfnLiteral += `\\n try {\\n`\n\n\t\tfor (let i = 0; i < app.event.request.length; i++) {\n\t\t\tconst hook = app.event.request[i]\n\t\t\tconst withReturn = hasReturn(hook.fn.toString())\n\t\t\tconst maybeAsync = isAsync(hook)\n\n\t\t\tconst endUnit = report('request.unit', {\n\t\t\t\tname: app.event.request[i].fn.name\n\t\t\t})\n\n\t\t\tif (withReturn) {\n\t\t\t\tfnLiteral += `re = mapEarlyResponse(\n\t\t\t\t\t${maybeAsync ? 'await' : ''} onRequest[${i}](ctx),\n\t\t\t\t\tctx.set,\n\t\t\t\t\trequest\n\t\t\t\t)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(re !== undefined) return re\\n`\n\t\t\t} else {\n\t\t\t\tfnLiteral += `${\n\t\t\t\t\tmaybeAsync ? 'await' : ''\n\t\t\t\t} onRequest[${i}](ctx)\\n`\n\t\t\t\tendUnit()\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += `} catch (error) {\n\t\t\treturn app.handleError(ctx, error)\n\t\t}`\n\n\t\tendReport()\n\n\t\tfnLiteral += init\n\t\tfnLiteral += `\\nctx.qi = qi\\n ctx.path = path\\n`\n\t} else {\n\t\tfnLiteral += init\n\t\tfnLiteral += `${hasTrace ? 'const id = +requestId.value++' : ''}\n\t\tconst ctx = {\n\t\t\trequest,\n\t\t\tstore,\n\t\t\tqi,\n\t\t\tpath,\n\t\t\tset: {\n\t\t\t\theaders: ${\n\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t: '{}'\n\t\t\t\t},\n\t\t\t\tstatus: 200\n\t\t\t},\n\t\t\terror\n\t\t\t${hasTrace ? ',$$requestId: id' : ''}\n\t\t\t${decoratorsLiteral}\n\t\t}`\n\n\t\treport('request', {\n\t\t\tunit: app.event.request.length,\n\t\t\tattribute:\n\t\t\t\tinference.trace.context ||\n\t\t\t\tinference.trace.store ||\n\t\t\t\tinference.trace.set\n\t\t\t\t\t? 'ctx'\n\t\t\t\t\t: ''\n\t\t})()\n\t}\n\n\tconst wsPaths = app.router.static.ws\n\tconst wsRouter = app.router.ws\n\n\tif (Object.keys(wsPaths).length || wsRouter.history.length) {\n\t\tfnLiteral += `\n\t\t\tif(request.method === 'GET') {\n\t\t\t\tswitch(path) {`\n\n\t\tfor (const [path, index] of Object.entries(wsPaths)) {\n\t\t\tfnLiteral += `\n\t\t\t\t\tcase '${path}':\n\t\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket')\n\t\t\t\t\t\t\treturn st${index}(ctx)\n\n\t\t\t\t\t\tbreak`\n\t\t}\n\n\t\tfnLiteral += `\n\t\t\t\tdefault:\n\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket') {\n\t\t\t\t\t\tconst route = wsRouter.find('ws', path)\n\n\t\t\t\t\t\tif(route) {\n\t\t\t\t\t\t\tctx.params = route.params\n\n\t\t\t\t\t\t\treturn route.store(ctx)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\\n`\n\t}\n\n\tfnLiteral += `\n\t\tmap: switch(path) {\n\t\t\t${switchMap}\n\n\t\t\tdefault:\n\t\t\t\tbreak\n\t\t}\n\n\t\t${findDynamicRoute}\n\t}`\n\n\tconst handleError = composeErrorHandler(app) as any\n\n\t// @ts-ignore\n\tapp.handleError = handleError\n\n\treturn Function(\n\t\t'data',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\t// @ts-ignore\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\thandleError,\n\t\terror\n\t})\n}\n\nexport const composeErrorHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tlet fnLiteral = `const {\n\t\tapp: { event: { error: onErrorContainer, onResponse: resContainer } },\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t} = inject\n\n\tconst onError = onErrorContainer.map(x => x.fn)\n\tconst res = resContainer.map(x => x.fn)\n\n\treturn ${\n\t\tapp.event.error.find(isAsync) ? 'async' : ''\n\t} function(context, error, skipGlobal) {\n\t\tlet r\n\n\t\tconst { set } = context\n\n\t\tcontext.code = error.code\n\t\tcontext.error = error\n\n\t\tif(ELYSIA_RESPONSE in error) {\n\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\terror.message = error.response\n\t\t}\\n`\n\n\tfor (let i = 0; i < app.event.error.length; i++) {\n\t\tconst handler = app.event.error[i]\n\n\t\tconst response = `${\n\t\t\tisAsync(handler) ? 'await ' : ''\n\t\t}onError[${i}](context)`\n\n\t\tfnLiteral += '\\nif(skipGlobal !== true) {\\n'\n\n\t\tif (hasReturn(handler.fn.toString()))\n\t\t\tfnLiteral += `r = ${response}; if(r !== undefined) {\n\t\t\t\tif(r instanceof Response) return r\n\n\t\t\t\tconsole.log(r, error)\n\n\t\t\t\tif(r[ELYSIA_RESPONSE]) {\n\t\t\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\t\t\terror.message = error.response\n\t\t\t\t}\n\t\t\n\t\t\t\tif(set.status === 200) set.status = error.status\n\t\t\t\treturn mapResponse(r, set, context.request)\n\t\t\t}\\n`\n\t\telse fnLiteral += response + '\\n'\n\n\t\tfnLiteral += '\\n}\\n'\n\t}\n\n\tfnLiteral += `if(error.constructor.name === \"ValidationError\" || error.constructor.name === \"TransformDecodeError\") {\n\t\tset.status = error.status ?? 422\n\t\treturn new Response(\n\t\t\terror.message,\n\t\t\t{ \n\t\t\t\theaders: Object.assign(\n\t\t\t\t\t{ 'content-type': 'application/json'}, \n\t\t\t\t\tset.headers\n\t\t\t\t), \n\t\t\t\tstatus: set.status\n\t\t\t}\n\t\t)\n\t} else {\n\t\tif(error.code && typeof error.status === \"number\")\n\t\t\treturn new Response(\n\t\t\t\terror.message,\n\t\t\t\t{ headers: set.headers, status: error.status }\n\t\t\t)\n\n\t\treturn mapResponse(error, set, context.request)\n\t}\n}`\n\n\treturn Function(\n\t\t'inject',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const jitRoute = (\n\tindex: number\n) => `if(stc${index}) return stc${index}(ctx)\nif(st${index}.compose) return (stc${index} = st${index}.compose())(ctx)\n\nreturn st${index}(ctx)`\n",
26
- "import { type Elysia } from '.'\n\nimport { Value } from '@sinclair/typebox/value'\nimport { TypeCheck } from '@sinclair/typebox/compiler'\nimport type { TAnySchema } from '@sinclair/typebox'\n\nimport { parse as parseQuery } from 'fast-querystring'\n\n// @ts-expect-error\nimport decodeURIComponent from 'fast-decode-uri-component'\n\nimport { getCookieValidator, lifeCycleToFn, signCookie } from './utils'\nimport { ParseError, error } from './error'\n\nimport {\n\tmapEarlyResponse,\n\tmapResponse,\n\tmapCompactResponse,\n\tisNotEmpty\n} from './handler'\nimport {\n\tNotFoundError,\n\tValidationError,\n\tInternalServerError,\n\tERROR_CODE,\n\tELYSIA_RESPONSE\n} from './error'\n\nimport { Sucrose, sucrose } from './sucrose'\nimport { parseCookie, type CookieOptions } from './cookies'\n\nimport type {\n\tComposedHandler,\n\tHandler,\n\tHookContainer,\n\tLifeCycleStore,\n\tSchemaValidator,\n\tTraceEvent\n} from './types'\n\nconst headersHasToJSON = (new Headers() as Headers).toJSON\nconst requestId = { value: 0 }\n\nconst createReport = ({\n\thasTrace,\n\thasTraceSet = false,\n\taddFn,\n\tcondition = {}\n}: {\n\thasTrace: boolean | number\n\thasTraceSet?: boolean\n\taddFn(string: string): void\n\tcondition: Partial<Record<TraceEvent, boolean>>\n}) => {\n\tif (hasTrace) {\n\t\taddFn(`\\nconst reporter = getReporter()\\n`)\n\n\t\treturn (\n\t\t\tevent: TraceEvent,\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\tattribute = '',\n\t\t\t\tunit = 0\n\t\t\t}: {\n\t\t\t\tname?: string\n\t\t\t\tattribute?: string\n\t\t\t\tunit?: number\n\t\t\t} = {}\n\t\t) => {\n\t\t\tconst dotIndex = event.indexOf('.')\n\t\t\tconst isGroup = dotIndex === -1\n\n\t\t\tif (\n\t\t\t\tevent !== 'request' &&\n\t\t\t\tevent !== 'response' &&\n\t\t\t\t!condition[\n\t\t\t\t\t(isGroup\n\t\t\t\t\t\t? event\n\t\t\t\t\t\t: event.slice(0, dotIndex)) as keyof typeof condition\n\t\t\t\t]\n\t\t\t)\n\t\t\t\treturn () => {\n\t\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t\t}\n\n\t\t\tif (isGroup) name ||= event\n\t\t\telse name ||= 'anonymous'\n\n\t\t\taddFn(\n\t\t\t\t'\\n' +\n\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\tid,\n\t\t\t\t\tevent: '${event}',\n\t\t\t\t\ttype: 'begin',\n\t\t\t\t\tname: '${name}',\n\t\t\t\t\ttime: performance.now(),\n\t\t\t\t\t${isGroup ? `unit: ${unit},` : ''}\n\t\t\t\t\t${attribute}\n\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t'\\n'\n\t\t\t)\n\n\t\t\treturn () => {\n\t\t\t\taddFn(\n\t\t\t\t\t'\\n' +\n\t\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tevent: '${event}',\n\t\t\t\t\t\t\ttype: 'end',\n\t\t\t\t\t\t\ttime: performance.now()\n\t\t\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t\t'\\n'\n\t\t\t\t)\n\n\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t}\n\t\t}\n\t} else {\n\t\treturn () => () => {}\n\t}\n}\n\nexport const hasReturn = (fnLiteral: string) => {\n\tconst parenthesisEnd = fnLiteral.indexOf(')')\n\n\t// Is direct arrow function return eg. () => 1\n\tif (\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 2) === 61 &&\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 5) !== 123\n\t) {\n\t\treturn true\n\t}\n\n\treturn fnLiteral.includes('return')\n}\n\nconst composeValidationFactory = (\n\thasErrorHandler: boolean,\n\t{\n\t\tinjectResponse = '',\n\t\tnormalize = false\n\t}: {\n\t\tinjectResponse?: string\n\t\tnormalize?: boolean\n\t} = {}\n) => ({\n\tcomposeValidation: (type: string, value = `c.${type}`) =>\n\t\thasErrorHandler\n\t\t\t? `c.set.status = 422; throw new ValidationError('${type}', ${type}, ${value})`\n\t\t\t: `c.set.status = 422; return new ValidationError('${type}', ${type}, ${value}).toResponse(c.set.headers)`,\n\tcomposeResponseValidation: (name = 'r') => {\n\t\tconst returnError = hasErrorHandler\n\t\t\t? `throw new ValidationError('response', response[c.set.status], ${name})`\n\t\t\t: `return new ValidationError('response', response[c.set.status], ${name}).toResponse(c.set.headers)`\n\n\t\tlet code = '\\n' + injectResponse + '\\n'\n\n\t\tcode += `let er\n\t\t\n\t\tif(${name} && typeof ${name} === \"object\" && ELYSIA_RESPONSE in ${name})\n\t\t\ter = ${name}[ELYSIA_RESPONSE]\\n`\n\n\t\tif (normalize)\n\t\t\tcode += `\n\t\t\tif(!er && response[c.set.status]?.Clean)\n\t\t\t\t${name} = response[c.set.status]?.Clean(${name})\n\t\t\telse if(response[er]?.Clean)\n\t\t\t\t${name}.response = response[er]?.Clean(${name}.response)`\n\n\t\tcode += `\n\t\t\tif(er) {\n\t\t\t\tif(!(${name} instanceof Response) && response[er]?.Check(${name}.response) === false) {\n\t\t\t\t\tif(!(response instanceof Error)) {\n\t\t\t\t\t\tc.set.status = ${name}[ELYSIA_RESPONSE]\n\n\t\t\t\t\t\t${returnError}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if(!(${name} instanceof Response) && response[c.set.status]?.Check(${name}) === false) {\n\t\t\t\tif(!(response instanceof Error))\n\t\t\t\t\t${returnError}\n\t\t\t}\\n`\n\n\t\treturn code\n\t}\n})\n\nconst KindSymbol = Symbol.for('TypeBox.Kind')\n\nexport const hasType = (type: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (KindSymbol in schema && schema[KindSymbol] === type) return true\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasType(type, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasType(type, property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tif (KindSymbol in property && property[KindSymbol] === type)\n\t\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tschema.properties &&\n\t\tKindSymbol in schema.properties &&\n\t\tschema.properties[KindSymbol] === type\n\t)\n}\n\nexport const hasProperty = (expectedProperty: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\n\t\tif (!properties) return false\n\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (expectedProperty in property) return true\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasProperty(expectedProperty, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++) {\n\t\t\t\t\tif (hasProperty(expectedProperty, property.anyOf[i]))\n\t\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn expectedProperty in schema\n}\n\nconst TransformSymbol = Symbol.for('TypeBox.Transform')\n\nexport const hasTransform = (schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object' && schema.properties) {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasTransform(property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasTransform(property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tconst hasTransformSymbol = TransformSymbol in property\n\t\t\tif (hasTransformSymbol) return true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tTransformSymbol in schema ||\n\t\t(schema.properties && TransformSymbol in schema.properties)\n\t)\n}\n\n/**\n * This function will return the type of unioned if all unioned type is the same.\n * It's intent to use for content-type mapping only\n *\n * ```ts\n * t.Union([\n * t.Object({\n * password: t.String()\n * }),\n * t.Object({\n * token: t.String()\n * })\n * ])\n * ```\n */\nconst getUnionedType = (validator: TypeCheck<any> | undefined) => {\n\tif (!validator) return\n\n\t// @ts-ignore\n\tconst schema = validator?.schema\n\n\tif (schema && 'anyOf' in schema) {\n\t\tlet foundDifference = false\n\t\tconst type: string = schema.anyOf[0].type\n\n\t\tfor (const validator of schema.anyOf as { type: string }[]) {\n\t\t\tif (validator.type !== type) {\n\t\t\t\tfoundDifference = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (!foundDifference) return type\n\t}\n\n\t// @ts-ignore\n\treturn validator.schema?.type\n}\n\nconst matchFnReturn = /(?:return|=>) \\S+\\(/g\n\nexport const isAsync = (v: Function | HookContainer) => {\n\tconst fn = 'fn' in v ? v.fn : v\n\n\tif (fn.constructor.name === 'AsyncFunction') return true\n\n\tconst literal = fn.toString()\n\tif (literal.includes('=> response.clone(')) return false\n\n\treturn !!literal.match(matchFnReturn)\n}\n\nexport const composeHandler = ({\n\tapp,\n\tpath,\n\tmethod,\n\tlocalHook,\n\thooks,\n\tvalidator,\n\thandler,\n\tallowMeta = false,\n\tappInference: { event: eventInference, trace: traceInference }\n}: {\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n\tpath: string\n\tmethod: string\n\thooks: LifeCycleStore\n\tlocalHook: LifeCycleStore\n\tvalidator: SchemaValidator\n\thandler: unknown | Handler<any, any>\n\tallowMeta?: boolean\n\tappInference: {\n\t\tevent: Sucrose.Inference\n\t\ttrace: Sucrose.TraceInference\n\t}\n}): ComposedHandler => {\n\tconst isHandleFn = typeof handler === 'function'\n\n\tif (!isHandleFn)\n\t\thandler = mapResponse(handler, {\n\t\t\t// @ts-expect-error private property\n\t\t\theaders: app.setHeaders ?? {}\n\t\t})\n\n\tconst hasErrorHandler =\n\t\t(app.config.forceErrorEncapsulation &&\n\t\t\t(isHandleFn ||\n\t\t\t\thooks.afterHandle.length > 0 ||\n\t\t\t\thooks.beforeHandle.length > 0 ||\n\t\t\t\thooks.transform.length > 0)) ||\n\t\thooks.error.length > 0 ||\n\t\tapp.event.error.length > 0 ||\n\t\ttypeof Bun === 'undefined' ||\n\t\thooks.onResponse.length > 0 ||\n\t\thooks.onResponse.length > 0 ||\n\t\t!!hooks.trace.length\n\n\tconst handle = isHandleFn ? `handler(c)` : `handler`\n\tconst handleResponse = hooks.onResponse.length\n\t\t? `\\n;(async () => {${hooks.onResponse\n\t\t\t\t.map((_, i) => `await res${i}(c)`)\n\t\t\t\t.join(';')}})();\\n`\n\t\t: ''\n\n\tconst traceConditions: Record<\n\t\tExclude<TraceEvent, `${string}.unit` | 'request' | 'response' | 'exit'>,\n\t\tboolean\n\t> = traceInference\n\n\tconst hasTrace = hooks.trace.length > 0\n\tlet fnLiteral = ''\n\n\tconst inference = sucrose(\n\t\tObject.assign(localHook, {\n\t\t\thandler: handler as any\n\t\t}),\n\t\teventInference\n\t)\n\n\tconst hasQuery = inference.query || !!validator.query\n\n\tconst hasBody =\n\t\tmethod !== '$INTERNALWS' &&\n\t\tmethod !== 'GET' &&\n\t\tmethod !== 'HEAD' &&\n\t\thooks.type !== 'none' &&\n\t\t(inference.body || !!validator.body)\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\tconst hasDefaultHeaders =\n\t\tdefaultHeaders && !!Object.keys(defaultHeaders).length\n\n\t// ? defaultHeaders doesn't imply that user will use headers in handler\n\tconst hasHeaders = inference.headers || validator.headers\n\tconst hasCookie = inference.cookie || !!validator.cookie\n\n\tconst cookieValidator = hasCookie\n\t\t? getCookieValidator({\n\t\t\t\tvalidator: validator.cookie as any,\n\t\t\t\tdefaultConfig: app.config.cookie,\n\t\t\t\tdynamic: !!app.config.aot,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tconfig: validator.cookie?.config ?? {},\n\t\t\t\t// @ts-expect-error\n\t\t\t\tmodels: app.definitions.type\n\t\t })\n\t\t: undefined\n\n\t// @ts-ignore private property\n\tconst cookieMeta = cookieValidator?.config as {\n\t\tsecrets?: string | string[]\n\t\tsign: string[] | true\n\t\tproperties: { [x: string]: Object }\n\t}\n\n\tlet encodeCookie = ''\n\n\tif (cookieMeta?.sign) {\n\t\tif (!cookieMeta.secrets)\n\t\t\tthrow new Error(\n\t\t\t\t`t.Cookie required secret which is not set in (${method}) ${path}.`\n\t\t\t)\n\n\t\tconst secret = !cookieMeta.secrets\n\t\t\t? undefined\n\t\t\t: typeof cookieMeta.secrets === 'string'\n\t\t\t? cookieMeta.secrets\n\t\t\t: cookieMeta.secrets[0]\n\n\t\tencodeCookie += `const _setCookie = c.set.cookie\n\t\tif(_setCookie) {`\n\n\t\tif (cookieMeta.sign === true) {\n\t\t\tencodeCookie += `for(const [key, cookie] of Object.entries(_setCookie)) {\n\t\t\t\tc.set.cookie[key].value = await signCookie(cookie.value, '${secret}')\n\t\t\t}`\n\t\t} else\n\t\t\tfor (const name of cookieMeta.sign) {\n\t\t\t\tencodeCookie += `if(_setCookie['${name}']?.value) { c.set.cookie['${name}'].value = await signCookie(_setCookie['${name}'].value, '${secret}') }\\n`\n\t\t\t}\n\n\t\tencodeCookie += '}\\n'\n\t}\n\n\tconst normalize = app.config.normalize\n\n\tconst { composeValidation, composeResponseValidation } =\n\t\tcomposeValidationFactory(hasErrorHandler, {\n\t\t\tnormalize\n\t\t})\n\n\tif (hasHeaders) {\n\t\t// This function is Bun specific\n\t\t// @ts-ignore\n\t\tfnLiteral += headersHasToJSON\n\t\t\t? `c.headers = c.request.headers.toJSON()\\n`\n\t\t\t: `c.headers = {}\n for (const [key, value] of c.request.headers.entries())\n\t\t\t\t\tc.headers[key] = value\n\t\t\t\t`\n\t}\n\n\tif (hasCookie) {\n\t\tconst get = (name: keyof CookieOptions, defaultValue?: unknown) => {\n\t\t\t// @ts-ignore\n\t\t\tconst value = cookieMeta?.[name] ?? defaultValue\n\t\t\tif (!value)\n\t\t\t\treturn typeof defaultValue === 'string'\n\t\t\t\t\t? `${name}: \"${defaultValue}\",`\n\t\t\t\t\t: `${name}: ${defaultValue},`\n\n\t\t\tif (typeof value === 'string') return `${name}: '${value}',`\n\t\t\tif (value instanceof Date)\n\t\t\t\treturn `${name}: new Date(${value.getTime()}),`\n\n\t\t\treturn `${name}: ${value},`\n\t\t}\n\n\t\tconst options = cookieMeta\n\t\t\t? `{\n\t\t\tsecrets: ${\n\t\t\t\tcookieMeta.secrets !== undefined\n\t\t\t\t\t? typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t\t? `'${cookieMeta.secrets}'`\n\t\t\t\t\t\t: '[' +\n\t\t\t\t\t\t cookieMeta.secrets.reduce(\n\t\t\t\t\t\t\t\t(a, b) => a + `'${b}',`,\n\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t ) +\n\t\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\tsign: ${\n\t\t\t\tcookieMeta.sign === true\n\t\t\t\t\t? true\n\t\t\t\t\t: cookieMeta.sign !== undefined\n\t\t\t\t\t? '[' +\n\t\t\t\t\t cookieMeta.sign.reduce((a, b) => a + `'${b}',`, '') +\n\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\t${get('domain')}\n\t\t\t${get('expires')}\n\t\t\t${get('httpOnly')}\n\t\t\t${get('maxAge')}\n\t\t\t${get('path', '/')}\n\t\t\t${get('priority')}\n\t\t\t${get('sameSite')}\n\t\t\t${get('secure')}\n\t\t}`\n\t\t\t: 'undefined'\n\n\t\tif (hasHeaders)\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${options})\\n`\n\t\telse\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${options})\\n`\n\t}\n\n\tif (hasQuery) {\n\t\tlet destructured = [] as string[]\n\n\t\t// @ts-ignore\n\t\tif (validator.query && validator.query.schema.type === 'object') {\n\t\t\t// @ts-ignore\n\t\t\tdestructured = Object.keys(validator.query.schema.properties)\n\t\t} else\n\t\t\tfor (const query of inference.queries)\n\t\t\t\tif (destructured.indexOf(query) === -1) destructured.push(query)\n\n\t\tif (\n\t\t\tapp.config.forceDynamicQuery === true ||\n\t\t\tinference.unknownQueries === true ||\n\t\t\t!destructured.length\n\t\t) {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tc.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\\\+/g, ' '))\n\n\t\t\t\tfor(const key of Object.keys(c.query))\n\t\t\t\t\tc.query[key] = decodeURIComponent(c.query[key])\n\t\t\t} else c.query = {}`\n\t\t} else {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tlet url = c.request.url.slice(c.qi).replace(/\\\\+/g, ' ')\n\n\t\t\t\t${destructured\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(name, index) => `\n\t\t\t\t\t\t${index === 0 ? 'let' : ''} memory = url.indexOf('&${name}=')\n\t\t\t\t\t\tif(memory === -1) memory = url.indexOf('?${name}=')\n\t\t\t\t\t\tlet a${index}\n\n\t\t\t\t\t\tif(memory !== -1) {\n\t\t\t\t\t\t\tconst start = memory + ${name.length + 2}\n\t\t\t\t\t\t\tmemory = url.indexOf('&', start)\n\n\t\t\t\t\t\t\tif(memory === -1) a${index} = decodeURIComponent(url.slice(start))\n\t\t\t\t\t\t\telse a${index} = decodeURIComponent(url.slice(start, memory))\n\t\t\t\t\t\t}`\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n')}\n\n\t\t\t\tc.query = {\n\t\t\t\t\t${destructured.map((name, index) => `'${name}': a${index}`).join(', ')}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tc.query = {}\n\t\t\t}`\n\t\t}\n\t}\n\n\tconst hasTraceSet = traceInference.set\n\tconst hasSet =\n\t\tinference.cookie ||\n\t\tinference.set ||\n\t\thasTraceSet ||\n\t\thasHeaders ||\n\t\t(isHandleFn && hasDefaultHeaders)\n\n\tif (hasTrace) fnLiteral += '\\nconst id = c.$$requestId\\n'\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet,\n\t\tcondition: traceConditions,\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tfnLiteral += hasErrorHandler ? '\\n try {\\n' : ''\n\n\tif (hasTraceSet) {\n\t\tfnLiteral += `\\nconst traceDone = Promise.all([`\n\t\tfor (let i = 0; i < hooks.trace.length; i++) {\n\t\t\tfnLiteral += `new Promise(r => { reporter.once(\\`res\\${id}.${i}\\`, r) }),`\n\t\t}\n\t\tfnLiteral += `])\\n`\n\t}\n\n\tconst isAsyncHandler = typeof handler === 'function' && isAsync(handler)\n\n\tconst maybeAsync =\n\t\thasCookie ||\n\t\thasBody ||\n\t\thasTraceSet ||\n\t\tisAsyncHandler ||\n\t\t!!hooks.mapResponse.length ||\n\t\thooks.parse.length > 0 ||\n\t\thooks.afterHandle.some(isAsync) ||\n\t\thooks.beforeHandle.some(isAsync) ||\n\t\thooks.transform.some(isAsync)\n\n\tconst endParse = report('parse', {\n\t\tunit: hooks.parse.length\n\t})\n\n\tif (hasBody) {\n\t\tconst type = getUnionedType(validator?.body)\n\n\t\tif (hooks.type && !Array.isArray(hooks.type)) {\n\t\t\tif (hooks.type) {\n\t\t\t\tswitch (hooks.type) {\n\t\t\t\t\tcase 'json':\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\tif (hasErrorHandler)\n\t\t\t\t\t\t\tfnLiteral += `const tempBody = await c.request.text()\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t\t}`\n\t\t\t\t\t\telse fnLiteral += `c.body = await c.request.json()`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text':\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.text()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'urlencoded':\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tfnLiteral += `c.body = parseQuery(await c.request.text())\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'arrayBuffer':\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.arrayBuffer()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'formdata':\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tfnLiteral += `c.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (hooks.parse.length) fnLiteral += '}}'\n\t\t} else {\n\t\t\tconst getAotParser = () => {\n\t\t\t\tif (hooks.parse.length && type && !Array.isArray(hooks.type)) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst schema = validator?.body?.schema\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof schema === 'object' &&\n\t\t\t\t\t\t(hasType('File', schema) || hasType('Files', schema))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn `c.body = {}\n\n\t\t\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t\t\t}`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst aotParse = getAotParser()\n\n\t\t\tif (aotParse) fnLiteral += aotParse\n\t\t\telse {\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t\tfnLiteral += hasHeaders\n\t\t\t\t\t? `let contentType = c.headers['content-type']`\n\t\t\t\t\t: `let contentType = c.request.headers.get('content-type')`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tif (contentType) {\n\t\t\t\t\tconst index = contentType.indexOf(';')\n\t\t\t\t\tif (index !== -1) contentType = contentType.substring(0, index)\\n`\n\n\t\t\t\tif (hooks.parse.length) {\n\t\t\t\t\tfnLiteral += `let used = false\\n`\n\n\t\t\t\t\tconst endReport = report('parse', {\n\t\t\t\t\t\tunit: hooks.parse.length\n\t\t\t\t\t})\n\n\t\t\t\t\tfor (let i = 0; i < hooks.parse.length; i++) {\n\t\t\t\t\t\tconst endUnit = report('parse.unit', {\n\t\t\t\t\t\t\tname: hooks.parse[i].fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tconst name = `bo${i}`\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `if(!used) {\\n`\n\n\t\t\t\t\t\tfnLiteral += `let ${name} = parse[${i}](c, contentType)\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} instanceof Promise) ${name} = await ${name}\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} !== undefined) { c.body = ${name}; used = true }\\n`\n\n\t\t\t\t\t\tendUnit()\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `}`\n\t\t\t\t\t}\n\n\t\t\t\t\tendReport()\n\t\t\t\t}\n\n\t\t\t\tif (hooks.parse.length) fnLiteral += `if (!used)`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tswitch (contentType) {\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t${\n\t\t\t\t\t\t\thasErrorHandler\n\t\t\t\t\t\t\t\t? `\n\t\t\t\t\t\tconst tempBody = await c.request.text()\n\t\t\t\t\t\t\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t: `c.body = await c.request.json()\\n`\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tc.body = await c.request.text()\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tc.body = parseQuery(await c.request.text())\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tc.body = await c.request.arrayBuffer();\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tc.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\\n`\n\n\t\t\t\tfnLiteral += '}\\n'\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += '\\n'\n\t}\n\n\tendParse()\n\n\tif (hooks?.transform) {\n\t\tconst endTransform = report('transform', {\n\t\t\tunit: hooks.transform.length\n\t\t})\n\n\t\tif (hooks.transform.length) fnLiteral += '\\nlet transformed\\n'\n\n\t\tfor (let i = 0; i < hooks.transform.length; i++) {\n\t\t\tconst transform = hooks.transform[i]\n\n\t\t\tconst endUnit = report('transform.unit', {\n\t\t\t\tname: transform.fn.name\n\t\t\t})\n\n\t\t\tfnLiteral += isAsync(transform)\n\t\t\t\t? `transformed = await transform[${i}](c)\\n`\n\t\t\t\t: `transformed = transform[${i}](c)\\n`\n\n\t\t\tfnLiteral += `if(transformed?.[ELYSIA_RESPONSE])\n\t\t\t\tthrow transformed\n\t\t\telse\n\t\t\t\tObject.assign(c, transformed)\\n`\n\n\t\t\tendUnit()\n\t\t}\n\n\t\tendTransform()\n\t}\n\n\tif (validator) {\n\t\tfnLiteral += '\\n'\n\n\t\tif (validator.headers) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.headers.params))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.headers.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.headers['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(headers.Check(c.headers) === false) {\n\t\t\t\t${composeValidation('headers')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.headers.schema))\n\t\t\t\tfnLiteral += `\\nc.headers = headers.Decode(c.headers)\\n`\n\t\t}\n\n\t\tif (validator.params) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.params.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.params.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.params['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(params.Check(c.params) === false) {\n\t\t\t\t${composeValidation('params')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.params.schema))\n\t\t\t\tfnLiteral += `\\nc.params = params.Decode(c.params)\\n`\n\t\t}\n\n\t\tif (validator.query) {\n\t\t\tif (normalize) fnLiteral += 'c.query = query.Clean(c.query);\\n'\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.query.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.query.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed) fnLiteral += `c.query['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(query.Check(c.query) === false) {\n\t\t\t\t${composeValidation('query')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.query.schema))\n\t\t\t\t// Decode doesn't work with Object.create(null)\n\t\t\t\tfnLiteral += `\\nc.query = query.Decode(Object.assign({}, c.query))\\n`\n\t\t}\n\n\t\tif (validator.body) {\n\t\t\tif (normalize) fnLiteral += 'c.body = body.Clean(c.body);\\n'\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.body.schema))\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n \t\t\t\tc.body = Object.assign(${JSON.stringify(\n\t\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tvalidator.body.schema,\n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t) ?? {}\n\t\t\t\t\t)}, c.body)\n\n \t\t\t\tif(body.Check(c.query) === false) {\n \t\t\t\t${composeValidation('body')}\n \t\t\t}\n }`\n\t\t\telse\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n\t\t\t${composeValidation('body')}\n\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.body.schema))\n\t\t\t\tfnLiteral += `\\nc.body = body.Decode(c.body)\\n`\n\t\t}\n\n\t\t// @ts-ignore\n\t\tif (isNotEmpty(cookieValidator?.schema.properties ?? {})) {\n\t\t\tfnLiteral += `const cookieValue = {}\n \t\t\tfor(const [key, value] of Object.entries(c.cookie))\n \t\t\t\tcookieValue[key] = value.value\\n`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', cookieValidator.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tcookieValidator.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tfnLiteral += `cookieValue['${key}'] = ${\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: value\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(cookie.Check(cookieValue) === false) {\n\t\t\t\t${composeValidation('cookie', 'cookieValue')}\n\t\t\t}`\n\n\t\t\t// // @ts-ignore\n\t\t\t// if (hasTransform(validator.cookie.schema))\n\t\t\t// \tfnLiteral += `\\nc.cookie = params.Decode(c.cookie)\\n`\n\t\t}\n\t}\n\n\tif (hooks?.beforeHandle) {\n\t\tconst endBeforeHandle = report('beforeHandle', {\n\t\t\tunit: hooks.beforeHandle.length\n\t\t})\n\n\t\tlet hasResolve = false\n\n\t\tfor (let i = 0; i < hooks.beforeHandle.length; i++) {\n\t\t\tconst beforeHandle = hooks.beforeHandle[i]\n\n\t\t\tconst endUnit = report('beforeHandle.unit', {\n\t\t\t\tname: beforeHandle.fn.name\n\t\t\t})\n\n\t\t\tconst returning = hasReturn(beforeHandle.fn.toString())\n\n\t\t\tconst isResolver = beforeHandle.subType === 'resolve'\n\n\t\t\tif (isResolver) {\n\t\t\t\tif (!hasResolve) {\n\t\t\t\t\thasResolve = true\n\t\t\t\t\tfnLiteral += '\\nlet resolved\\n'\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `resolved = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `resolved = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tfnLiteral += `if(resolved[ELYSIA_RESPONSE])\n\t\t\t\t\t\tthrow resolved\n\t\t\t\t\telse\n\t\t\t\t\t\tObject.assign(c, resolved)\\n`\n\t\t\t} else if (!returning) {\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += `Object.assign(c, be);`\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `be = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `be = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(be !== undefined) {\\n`\n\t\t\t\tendBeforeHandle()\n\t\t\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\t\t\tunit: hooks.transform.length\n\t\t\t\t})\n\t\t\t\tif (hooks.afterHandle) {\n\t\t\t\t\treport('handle', {\n\t\t\t\t\t\tname: isHandleFn\n\t\t\t\t\t\t\t? (handler as Function).name\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t})()\n\n\t\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\t\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\t\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\t\t\t\tname: hook.fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tfnLiteral += `c.response = be\\n`\n\n\t\t\t\t\t\tif (!returning) {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `await afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t\t\t: `afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\t\t\t\tfnLiteral += `if(af !== undefined) { c.response = be = af }\\n`\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tendUnit()\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tendAfterHandle()\n\n\t\t\t\tif (validator.response)\n\t\t\t\t\tfnLiteral += composeResponseValidation('be')\n\n\t\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\t\tfnLiteral += `c.response = be`\n\n\t\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\t\t\t\tif(mr !== undefined) c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += encodeCookie\n\t\t\t\tfnLiteral += `return mapEarlyResponse(be, c.set, c.request)}\\n`\n\t\t\t}\n\t\t}\n\n\t\tendBeforeHandle()\n\t}\n\n\tif (hooks?.afterHandle.length) {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (hooks.afterHandle.length)\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = c.response = await ${handle};\\n`\n\t\t\t\t: `let r = c.response = ${handle};\\n`\n\t\telse\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\tendHandle()\n\n\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\tunit: hooks.afterHandle.length\n\t\t})\n\n\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\tname: hook.fn.name\n\t\t\t})\n\n\t\t\tif (!returning) {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tif (validator.response) {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += composeResponseValidation('af')\n\n\t\t\t\t\tfnLiteral += `c.response = af }`\n\t\t\t\t} else {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += `c.response = af}\\n`\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tendAfterHandle()\n\n\t\tfnLiteral += `r = c.response\\n`\n\n\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\tfnLiteral += encodeCookie\n\n\t\tif (hooks.mapResponse.length) {\n\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\tfnLiteral += `\\nmr = onMapResponse[${i}](c)\n\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\tif(mr !== undefined) c.response = mr\\n`\n\t\t\t}\n\t\t}\n\n\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t} else {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (validator.response || hooks.mapResponse.length) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) { \n\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else if (traceConditions.handle || hasCookie) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else {\n\t\t\tendHandle()\n\n\t\t\tconst handled = isAsyncHandler ? `await ${handle}` : handle\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(${handled}, c.set, c.request)\\n`\n\t\t\telse\n\t\t\t\tfnLiteral += `return mapCompactResponse(${handled}, c.request)\\n`\n\t\t}\n\t}\n\n\tif (hasErrorHandler || handleResponse) {\n\t\tfnLiteral += `\\n} catch(error) {`\n\t\tif (!maybeAsync) fnLiteral += `return (async () => {`\n\n\t\tfnLiteral += `const set = c.set\\nif (!set.status || set.status < 300) set.status = error?.status || 500\\n`\n\n\t\tconst endError = report('error', {\n\t\t\tunit: hooks.error.length\n\t\t})\n\n\t\tif (hooks.error.length) {\n\t\t\tfnLiteral += `\n\t\t\t\tc.error = error\n\t\t\t\tc.code = error.code ?? error[ERROR_CODE] ?? \"UNKNOWN\"\n\t\t\t`\n\n\t\t\tfor (let i = 0; i < hooks.error.length; i++) {\n\t\t\t\tconst name = `er${i}`\n\t\t\t\tconst endUnit = report('error.unit', {\n\t\t\t\t\tname: hooks.error[i].fn.name\n\t\t\t\t})\n\n\t\t\t\tfnLiteral += `\\nlet ${name} = handleErrors[${i}](c)\\n`\n\n\t\t\t\tif (isAsync(hooks.error[i]))\n\t\t\t\t\tfnLiteral += `if (${name} instanceof Promise) ${name} = await ${name}\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `${name} = mapEarlyResponse(${name}, set, c.request)\\n`\n\t\t\t\tfnLiteral += `if (${name}) {`\n\t\t\t\tfnLiteral += `return ${name} }\\n`\n\t\t\t}\n\t\t}\n\n\t\tendError()\n\n\t\tfnLiteral += `return handleError(c, error, true)\\n\\n`\n\n\t\tif (!maybeAsync) fnLiteral += '})()'\n\n\t\tfnLiteral += '}'\n\n\t\tif (handleResponse || hasTrace) {\n\t\t\tfnLiteral += ` finally { `\n\n\t\t\tconst endResponse = report('response', {\n\t\t\t\tunit: hooks.onResponse.length\n\t\t\t})\n\n\t\t\tfnLiteral += handleResponse\n\n\t\t\tendResponse()\n\n\t\t\tfnLiteral += `}`\n\t\t}\n\t}\n\n\tfnLiteral = `const {\n\t\thandler,\n\t\thandleError,\n\t\thooks: {\n\t\t\ttransform,\n\t\t\tresolve,\n\t\t\tbeforeHandle,\n\t\t\tafterHandle,\n\t\t\tmapResponse: onMapResponse,\n\t\t\tparse,\n\t\t\terror: handleErrors,\n\t\t\tonResponse\n\t\t},\n\t\tvalidator: {\n\t\t\tbody,\n\t\t\theaders,\n\t\t\tparams,\n\t\t\tquery,\n\t\t\tresponse,\n\t\t\tcookie\n\t\t},\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema,\n\t\tdefinitions,\n\t\tERROR_CODE,\n\t\tgetReporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t} = hooks\n\n\t${\n\t\thooks.onResponse.length\n\t\t\t? `const ${hooks.onResponse\n\t\t\t\t\t.map((x, i) => `res${i} = onResponse[${i}]`)\n\t\t\t\t\t.join(',')}`\n\t\t\t: ''\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function handle(c) {\n\t\t${hooks.beforeHandle.length ? 'let be' : ''}\n\t\t${hooks.afterHandle.length ? 'let af' : ''}\n\t\t${hooks.mapResponse.length ? 'let mr' : ''}\n\n\t\t${allowMeta ? 'c.schema = schema; c.defs = definitions' : ''}\n\t\t${fnLiteral}\n\t}`\n\n\tconst createHandler = Function('hooks', fnLiteral)\n\n\treturn createHandler({\n\t\thandler,\n\t\thooks: lifeCycleToFn(hooks),\n\t\tvalidator,\n\t\t// @ts-expect-error\n\t\thandleError: app.handleError,\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema: app.router.history,\n\t\t// @ts-expect-error\n\t\tdefinitions: app.definitions.type,\n\t\tERROR_CODE,\n\t\t// @ts-expect-error\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const composeGeneralHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tconst inference = {\n\t\tevent: {\n\t\t\t// @ts-expect-error\n\t\t\t...app.inference.event,\n\t\t\t// @ts-expect-error\n\t\t\tqueries: [...app.inference.event.queries]\n\t\t},\n\t\t// @ts-expect-error\n\t\ttrace: { ...app.inference.trace }\n\t}\n\n\tlet decoratorsLiteral = ''\n\tlet fnLiteral = ''\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\n\t// @ts-ignore\n\tfor (const key of Object.keys(app.singleton.decorator))\n\t\tdecoratorsLiteral += `,${key}: app.singleton.decorator.${key}`\n\n\tconst router = app.router\n\tconst hasTrace = app.event.trace.length > 0\n\n\tlet findDynamicRoute = `\n\tconst route = router.find(request.method, path) ${\n\t\trouter.http.root.ALL ? '?? router.find(\"ALL\", path)' : ''\n\t}\n\n\tif (route === null)\n\t\treturn ${\n\t\t\tapp.event.error.length\n\t\t\t\t? `app.handleError(ctx, notFound)`\n\t\t\t\t: app.event.request.length\n\t\t\t\t? `new Response(error404Message, {\n\t\t\t\t\tstatus: ctx.set.status === 200 ? 404 : ctx.set.status,\n\t\t\t\t\theaders: ctx.set.headers\n\t\t\t\t})`\n\t\t\t\t: `error404.clone()`\n\t\t}\n\n\tctx.params = route.params\\n`\n\n\tconst shouldPrecompile =\n\t\tapp.config.precompile === true ||\n\t\t(typeof app.config.precompile === 'object' &&\n\t\t\tapp.config.precompile.compose === true)\n\n\tif (!shouldPrecompile)\n\t\tfindDynamicRoute += `\n\t\t\tif(route.store.composed)\n\t\t\t\treturn route.store.composed(ctx)\n\n\t\t\tif(route.store.compose)\n\t\t\t\treturn (route.store.compose())(ctx)`\n\telse findDynamicRoute += `return route.store(ctx)`\n\n\tfindDynamicRoute += '\\n'\n\n\tlet switchMap = ``\n\tfor (const [path, { code, all }] of Object.entries(router.static.http.map))\n\t\tswitchMap += `case '${path}':\\nswitch(request.method) {\\n${code}\\n${\n\t\t\tall ?? `default: break map`\n\t\t}}\\n\\n`\n\n\tconst maybeAsync = app.event.request.some(isAsync)\n\n\tconst init = `\\n\n\tconst url = request.url\n\tconst s = url.indexOf('/', 11)\n\tconst qi = url.indexOf('?', s + 1)\n\tlet path\n\tif(qi === -1)\n\t\tpath = url.substring(s)\n\telse \n\t\tpath = url.substring(s, qi)\\n`\n\n\tfnLiteral += `const {\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\trequestId,\n\t\tgetReporter,\n\t\thandleError,\n\t\terror\n\t} = data\n\n\tconst store = app.singleton.store\n\tconst staticRouter = app.router.static.http\n\tconst wsRouter = app.router.ws\n\tconst router = app.router.http\n\n\tconst notFound = new NotFoundError()\n\n\t${\n\t\tapp.event.request.length\n\t\t\t? `const onRequest = app.event.request.map(x => x.fn)`\n\t\t\t: ''\n\t}\n\t${router.static.http.variables}\n\t${\n\t\tapp.event.error.length\n\t\t\t? ''\n\t\t\t: `\n\tconst error404Message = notFound.message.toString()\n\tconst error404 = new Response(error404Message, { status: 404 });\n\t`\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function map(request) {\\n`\n\n\tif (app.event.request.length) fnLiteral += `let re`\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet: inference.trace.set,\n\t\tcondition: {\n\t\t\trequest: inference.trace.request\n\t\t},\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tif (app.event.request.length) {\n\t\tfnLiteral += `\n\t\t\t${hasTrace ? 'const id = +requestId.value++' : ''}\n\n\t\t\tconst ctx = {\n\t\t\t\trequest,\n\t\t\t\tstore,\n\t\t\t\tset: {\n\t\t\t\t\theaders: ${\n\t\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t\t: '{}'\n\t\t\t\t\t},\n\t\t\t\t\tstatus: 200\n\t\t\t\t},\n\t\t\t\terror\n\t\t\t\t${hasTrace ? ',$$requestId: +id' : ''}\n\t\t\t\t${decoratorsLiteral}\n\t\t\t}\n\t\t`\n\n\t\tconst endReport = report('request', {\n\t\t\tattribute: 'ctx',\n\t\t\tunit: app.event.request.length\n\t\t})\n\n\t\tfnLiteral += `\\n try {\\n`\n\n\t\tfor (let i = 0; i < app.event.request.length; i++) {\n\t\t\tconst hook = app.event.request[i]\n\t\t\tconst withReturn = hasReturn(hook.fn.toString())\n\t\t\tconst maybeAsync = isAsync(hook)\n\n\t\t\tconst endUnit = report('request.unit', {\n\t\t\t\tname: app.event.request[i].fn.name\n\t\t\t})\n\n\t\t\tif (withReturn) {\n\t\t\t\tfnLiteral += `re = mapEarlyResponse(\n\t\t\t\t\t${maybeAsync ? 'await' : ''} onRequest[${i}](ctx),\n\t\t\t\t\tctx.set,\n\t\t\t\t\trequest\n\t\t\t\t)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(re !== undefined) return re\\n`\n\t\t\t} else {\n\t\t\t\tfnLiteral += `${\n\t\t\t\t\tmaybeAsync ? 'await' : ''\n\t\t\t\t} onRequest[${i}](ctx)\\n`\n\t\t\t\tendUnit()\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += `} catch (error) {\n\t\t\treturn app.handleError(ctx, error)\n\t\t}`\n\n\t\tendReport()\n\n\t\tfnLiteral += init\n\t\tfnLiteral += `\\nctx.qi = qi\\n ctx.path = path\\n`\n\t} else {\n\t\tfnLiteral += init\n\t\tfnLiteral += `${hasTrace ? 'const id = +requestId.value++' : ''}\n\t\tconst ctx = {\n\t\t\trequest,\n\t\t\tstore,\n\t\t\tqi,\n\t\t\tpath,\n\t\t\tset: {\n\t\t\t\theaders: ${\n\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t: '{}'\n\t\t\t\t},\n\t\t\t\tstatus: 200\n\t\t\t},\n\t\t\terror\n\t\t\t${hasTrace ? ',$$requestId: id' : ''}\n\t\t\t${decoratorsLiteral}\n\t\t}`\n\n\t\treport('request', {\n\t\t\tunit: app.event.request.length,\n\t\t\tattribute:\n\t\t\t\tinference.trace.context ||\n\t\t\t\tinference.trace.store ||\n\t\t\t\tinference.trace.set\n\t\t\t\t\t? 'ctx'\n\t\t\t\t\t: ''\n\t\t})()\n\t}\n\n\tconst wsPaths = app.router.static.ws\n\tconst wsRouter = app.router.ws\n\n\tif (Object.keys(wsPaths).length || wsRouter.history.length) {\n\t\tfnLiteral += `\n\t\t\tif(request.method === 'GET') {\n\t\t\t\tswitch(path) {`\n\n\t\tfor (const [path, index] of Object.entries(wsPaths)) {\n\t\t\tfnLiteral += `\n\t\t\t\t\tcase '${path}':\n\t\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket')\n\t\t\t\t\t\t\treturn st${index}(ctx)\n\n\t\t\t\t\t\tbreak`\n\t\t}\n\n\t\tfnLiteral += `\n\t\t\t\tdefault:\n\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket') {\n\t\t\t\t\t\tconst route = wsRouter.find('ws', path)\n\n\t\t\t\t\t\tif(route) {\n\t\t\t\t\t\t\tctx.params = route.params\n\n\t\t\t\t\t\t\treturn route.store(ctx)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\\n`\n\t}\n\n\tfnLiteral += `\n\t\tmap: switch(path) {\n\t\t\t${switchMap}\n\n\t\t\tdefault:\n\t\t\t\tbreak\n\t\t}\n\n\t\t${findDynamicRoute}\n\t}`\n\n\tconst handleError = composeErrorHandler(app) as any\n\n\t// @ts-ignore\n\tapp.handleError = handleError\n\n\treturn Function(\n\t\t'data',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\t// @ts-ignore\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\thandleError,\n\t\terror\n\t})\n}\n\nexport const composeErrorHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tlet fnLiteral = `const {\n\t\tapp: { event: { error: onErrorContainer, onResponse: resContainer } },\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t} = inject\n\n\tconst onError = onErrorContainer.map(x => x.fn)\n\tconst res = resContainer.map(x => x.fn)\n\n\treturn ${\n\t\tapp.event.error.find(isAsync) ? 'async' : ''\n\t} function(context, error, skipGlobal) {\n\t\tlet r\n\n\t\tconst { set } = context\n\n\t\tcontext.code = error.code\n\t\tcontext.error = error\n\n\t\tif(ELYSIA_RESPONSE in error) {\n\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\terror.message = error.response\n\t\t}\\n`\n\n\tfor (let i = 0; i < app.event.error.length; i++) {\n\t\tconst handler = app.event.error[i]\n\n\t\tconst response = `${\n\t\t\tisAsync(handler) ? 'await ' : ''\n\t\t}onError[${i}](context)`\n\n\t\tfnLiteral += '\\nif(skipGlobal !== true) {\\n'\n\n\t\tif (hasReturn(handler.fn.toString()))\n\t\t\tfnLiteral += `r = ${response}; if(r !== undefined) {\n\t\t\t\tif(r instanceof Response) return r\n\n\t\t\t\tconsole.log(r, error)\n\n\t\t\t\tif(r[ELYSIA_RESPONSE]) {\n\t\t\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\t\t\terror.message = error.response\n\t\t\t\t}\n\t\t\n\t\t\t\tif(set.status === 200) set.status = error.status\n\t\t\t\treturn mapResponse(r, set, context.request)\n\t\t\t}\\n`\n\t\telse fnLiteral += response + '\\n'\n\n\t\tfnLiteral += '\\n}\\n'\n\t}\n\n\tfnLiteral += `if(error.constructor.name === \"ValidationError\" || error.constructor.name === \"TransformDecodeError\") {\n\t\tset.status = error.status ?? 422\n\t\treturn new Response(\n\t\t\terror.message,\n\t\t\t{ \n\t\t\t\theaders: Object.assign(\n\t\t\t\t\t{ 'content-type': 'application/json'}, \n\t\t\t\t\tset.headers\n\t\t\t\t), \n\t\t\t\tstatus: set.status\n\t\t\t}\n\t\t)\n\t} else {\n\t\tif(error.code && typeof error.status === \"number\")\n\t\t\treturn new Response(\n\t\t\t\terror.message,\n\t\t\t\t{ headers: set.headers, status: error.status }\n\t\t\t)\n\n\t\treturn mapResponse(error, set, context.request)\n\t}\n}`\n\n\treturn Function(\n\t\t'inject',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const jitRoute = (\n\tindex: number\n) => `if(stc${index}) return stc${index}(ctx)\nif(st${index}.compose) return (stc${index} = st${index}.compose())(ctx)\n\nreturn st${index}(ctx)`\n",
25
+ "import { type Elysia } from '.'\n\nimport { Value } from '@sinclair/typebox/value'\nimport { TypeCheck } from '@sinclair/typebox/compiler'\nimport type { TAnySchema } from '@sinclair/typebox'\n\nimport { parse as parseQuery } from 'fast-querystring'\n\n// @ts-expect-error\nimport decodeURIComponent from 'fast-decode-uri-component'\n\nimport { getCookieValidator, lifeCycleToFn, signCookie } from './utils'\nimport { ParseError, error } from './error'\n\nimport {\n\tmapEarlyResponse,\n\tmapResponse,\n\tmapCompactResponse,\n\tisNotEmpty\n} from './handler'\nimport {\n\tNotFoundError,\n\tValidationError,\n\tInternalServerError,\n\tERROR_CODE,\n\tELYSIA_RESPONSE\n} from './error'\n\nimport { Sucrose, sucrose } from './sucrose'\nimport { parseCookie, type CookieOptions } from './cookies'\n\nimport type {\n\tComposedHandler,\n\tHandler,\n\tHookContainer,\n\tLifeCycleStore,\n\tSchemaValidator,\n\tTraceEvent\n} from './types'\n\nconst headersHasToJSON = (new Headers() as Headers).toJSON\nconst requestId = { value: 0 }\n\nconst createReport = ({\n\thasTrace,\n\thasTraceSet = false,\n\taddFn,\n\tcondition = {}\n}: {\n\thasTrace: boolean | number\n\thasTraceSet?: boolean\n\taddFn(string: string): void\n\tcondition: Partial<Record<TraceEvent, boolean>>\n}) => {\n\tif (hasTrace) {\n\t\taddFn(`\\nconst reporter = getReporter()\\n`)\n\n\t\treturn (\n\t\t\tevent: TraceEvent,\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\tattribute = '',\n\t\t\t\tunit = 0\n\t\t\t}: {\n\t\t\t\tname?: string\n\t\t\t\tattribute?: string\n\t\t\t\tunit?: number\n\t\t\t} = {}\n\t\t) => {\n\t\t\tconst dotIndex = event.indexOf('.')\n\t\t\tconst isGroup = dotIndex === -1\n\n\t\t\tif (\n\t\t\t\tevent !== 'request' &&\n\t\t\t\tevent !== 'response' &&\n\t\t\t\t!condition[\n\t\t\t\t\t(isGroup\n\t\t\t\t\t\t? event\n\t\t\t\t\t\t: event.slice(0, dotIndex)) as keyof typeof condition\n\t\t\t\t]\n\t\t\t)\n\t\t\t\treturn () => {\n\t\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t\t}\n\n\t\t\tif (isGroup) name ||= event\n\t\t\telse name ||= 'anonymous'\n\n\t\t\taddFn(\n\t\t\t\t'\\n' +\n\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\tid,\n\t\t\t\t\tevent: '${event}',\n\t\t\t\t\ttype: 'begin',\n\t\t\t\t\tname: '${name}',\n\t\t\t\t\ttime: performance.now(),\n\t\t\t\t\t${isGroup ? `unit: ${unit},` : ''}\n\t\t\t\t\t${attribute}\n\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t'\\n'\n\t\t\t)\n\n\t\t\treturn () => {\n\t\t\t\taddFn(\n\t\t\t\t\t'\\n' +\n\t\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tevent: '${event}',\n\t\t\t\t\t\t\ttype: 'end',\n\t\t\t\t\t\t\ttime: performance.now()\n\t\t\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t\t'\\n'\n\t\t\t\t)\n\n\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t}\n\t\t}\n\t} else {\n\t\treturn () => () => {}\n\t}\n}\n\nexport const hasReturn = (fnLiteral: string) => {\n\tconst parenthesisEnd = fnLiteral.indexOf(')')\n\n\t// Is direct arrow function return eg. () => 1\n\tif (\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 2) === 61 &&\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 5) !== 123\n\t) {\n\t\treturn true\n\t}\n\n\treturn fnLiteral.includes('return')\n}\n\nconst composeValidationFactory = (\n\thasErrorHandler: boolean,\n\t{\n\t\tinjectResponse = '',\n\t\tnormalize = false\n\t}: {\n\t\tinjectResponse?: string\n\t\tnormalize?: boolean\n\t} = {}\n) => ({\n\tcomposeValidation: (type: string, value = `c.${type}`) =>\n\t\thasErrorHandler\n\t\t\t? `c.set.status = 422; throw new ValidationError('${type}', ${type}, ${value})`\n\t\t\t: `c.set.status = 422; return new ValidationError('${type}', ${type}, ${value}).toResponse(c.set.headers)`,\n\tcomposeResponseValidation: (name = 'r') => {\n\t\tconst returnError = hasErrorHandler\n\t\t\t? `throw new ValidationError('response', response[c.set.status], ${name})`\n\t\t\t: `return new ValidationError('response', response[c.set.status], ${name}).toResponse(c.set.headers)`\n\n\t\tlet code = '\\n' + injectResponse + '\\n'\n\n\t\tcode += `let er\n\t\t\n\t\tif(${name} && typeof ${name} === \"object\" && ELYSIA_RESPONSE in ${name})\n\t\t\ter = ${name}[ELYSIA_RESPONSE]\\n`\n\n\t\tif (normalize)\n\t\t\tcode += `\n\t\t\tif(!er && response[c.set.status]?.Clean)\n\t\t\t\t${name} = response[c.set.status]?.Clean(${name})\n\t\t\telse if(response[er]?.Clean)\n\t\t\t\t${name}.response = response[er]?.Clean(${name}.response)`\n\n\t\tcode += `\n\t\t\tif(er) {\n\t\t\t\tif(!(${name} instanceof Response) && response[er]?.Check(${name}.response) === false) {\n\t\t\t\t\tif(!(response instanceof Error)) {\n\t\t\t\t\t\tc.set.status = ${name}[ELYSIA_RESPONSE]\n\n\t\t\t\t\t\t${returnError}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if(!(${name} instanceof Response) && response[c.set.status]?.Check(${name}) === false) {\n\t\t\t\tif(!(response instanceof Error))\n\t\t\t\t\t${returnError}\n\t\t\t}\\n`\n\n\t\treturn code\n\t}\n})\n\nconst KindSymbol = Symbol.for('TypeBox.Kind')\n\nexport const hasType = (type: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (KindSymbol in schema && schema[KindSymbol] === type) return true\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasType(type, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasType(type, property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tif (KindSymbol in property && property[KindSymbol] === type)\n\t\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tschema.properties &&\n\t\tKindSymbol in schema.properties &&\n\t\tschema.properties[KindSymbol] === type\n\t)\n}\n\nexport const hasProperty = (expectedProperty: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\n\t\tif (!properties) return false\n\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (expectedProperty in property) return true\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasProperty(expectedProperty, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++) {\n\t\t\t\t\tif (hasProperty(expectedProperty, property.anyOf[i]))\n\t\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn expectedProperty in schema\n}\n\nconst TransformSymbol = Symbol.for('TypeBox.Transform')\n\nexport const hasTransform = (schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object' && schema.properties) {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasTransform(property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasTransform(property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tconst hasTransformSymbol = TransformSymbol in property\n\t\t\tif (hasTransformSymbol) return true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tTransformSymbol in schema ||\n\t\t(schema.properties && TransformSymbol in schema.properties)\n\t)\n}\n\n/**\n * This function will return the type of unioned if all unioned type is the same.\n * It's intent to use for content-type mapping only\n *\n * ```ts\n * t.Union([\n * t.Object({\n * password: t.String()\n * }),\n * t.Object({\n * token: t.String()\n * })\n * ])\n * ```\n */\nconst getUnionedType = (validator: TypeCheck<any> | undefined) => {\n\tif (!validator) return\n\n\t// @ts-ignore\n\tconst schema = validator?.schema\n\n\tif (schema && 'anyOf' in schema) {\n\t\tlet foundDifference = false\n\t\tconst type: string = schema.anyOf[0].type\n\n\t\tfor (const validator of schema.anyOf as { type: string }[]) {\n\t\t\tif (validator.type !== type) {\n\t\t\t\tfoundDifference = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (!foundDifference) return type\n\t}\n\n\t// @ts-ignore\n\treturn validator.schema?.type\n}\n\nconst matchFnReturn = /(?:return|=>) \\S+\\(/g\n\nexport const isAsync = (v: Function | HookContainer) => {\n\tconst fn = 'fn' in v ? v.fn : v\n\n\tif (fn.constructor.name === 'AsyncFunction') return true\n\n\tconst literal = fn.toString()\n\tif (literal.includes('=> response.clone(')) return false\n\n\treturn !!literal.match(matchFnReturn)\n}\n\nexport const composeHandler = ({\n\tapp,\n\tpath,\n\tmethod,\n\tlocalHook,\n\thooks,\n\tvalidator,\n\thandler,\n\tallowMeta = false,\n\tappInference: { event: eventInference, trace: traceInference }\n}: {\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n\tpath: string\n\tmethod: string\n\thooks: LifeCycleStore\n\tlocalHook: LifeCycleStore\n\tvalidator: SchemaValidator\n\thandler: unknown | Handler<any, any>\n\tallowMeta?: boolean\n\tappInference: {\n\t\tevent: Sucrose.Inference\n\t\ttrace: Sucrose.TraceInference\n\t}\n}): ComposedHandler => {\n\tconst isHandleFn = typeof handler === 'function'\n\n\tif (!isHandleFn)\n\t\thandler = mapResponse(handler, {\n\t\t\t// @ts-expect-error private property\n\t\t\theaders: app.setHeaders ?? {}\n\t\t})\n\n\tconst hasErrorHandler =\n\t\t(app.config.forceErrorEncapsulation &&\n\t\t\t(isHandleFn ||\n\t\t\t\thooks.afterHandle.length > 0 ||\n\t\t\t\thooks.beforeHandle.length > 0 ||\n\t\t\t\thooks.transform.length > 0)) ||\n\t\thooks.error.length > 0 ||\n\t\tapp.event.error.length > 0 ||\n\t\ttypeof Bun === 'undefined' ||\n\t\thooks.onResponse.length > 0 ||\n\t\thooks.onResponse.length > 0 ||\n\t\t!!hooks.trace.length\n\n\tconst handle = isHandleFn ? `handler(c)` : `handler`\n\tconst handleResponse = hooks.onResponse.length\n\t\t? `\\n;(async () => {${hooks.onResponse\n\t\t\t\t.map((_, i) => `await res${i}(c)`)\n\t\t\t\t.join(';')}})();\\n`\n\t\t: ''\n\n\tconst traceConditions: Record<\n\t\tExclude<TraceEvent, `${string}.unit` | 'request' | 'response' | 'exit'>,\n\t\tboolean\n\t> = traceInference\n\n\tconst hasTrace = hooks.trace.length > 0\n\tlet fnLiteral = ''\n\n\tconst inference = sucrose(\n\t\tObject.assign(localHook, {\n\t\t\thandler: handler as any\n\t\t}),\n\t\teventInference\n\t)\n\n\tconst hasQuery = inference.query || !!validator.query\n\n\tconst hasBody =\n\t\tmethod !== '$INTERNALWS' &&\n\t\tmethod !== 'GET' &&\n\t\tmethod !== 'HEAD' &&\n\t\thooks.type !== 'none' &&\n\t\t(inference.body || !!validator.body)\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\tconst hasDefaultHeaders =\n\t\tdefaultHeaders && !!Object.keys(defaultHeaders).length\n\n\t// ? defaultHeaders doesn't imply that user will use headers in handler\n\tconst hasHeaders = inference.headers || validator.headers\n\tconst hasCookie = inference.cookie || !!validator.cookie\n\n\tconst cookieValidator = hasCookie\n\t\t? getCookieValidator({\n\t\t\t\tvalidator: validator.cookie as any,\n\t\t\t\tdefaultConfig: app.config.cookie,\n\t\t\t\tdynamic: !!app.config.aot,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tconfig: validator.cookie?.config ?? {},\n\t\t\t\t// @ts-expect-error\n\t\t\t\tmodels: app.definitions.type\n\t\t })\n\t\t: undefined\n\n\t// @ts-ignore private property\n\tconst cookieMeta = cookieValidator?.config as {\n\t\tsecrets?: string | string[]\n\t\tsign: string[] | true\n\t\tproperties: { [x: string]: Object }\n\t}\n\n\tlet encodeCookie = ''\n\n\tif (cookieMeta?.sign) {\n\t\tif (!cookieMeta.secrets)\n\t\t\tthrow new Error(\n\t\t\t\t`t.Cookie required secret which is not set in (${method}) ${path}.`\n\t\t\t)\n\n\t\tconst secret = !cookieMeta.secrets\n\t\t\t? undefined\n\t\t\t: typeof cookieMeta.secrets === 'string'\n\t\t\t? cookieMeta.secrets\n\t\t\t: cookieMeta.secrets[0]\n\n\t\tencodeCookie += `const _setCookie = c.set.cookie\n\t\tif(_setCookie) {`\n\n\t\tif (cookieMeta.sign === true) {\n\t\t\tencodeCookie += `for(const [key, cookie] of Object.entries(_setCookie)) {\n\t\t\t\tc.set.cookie[key].value = await signCookie(cookie.value, '${secret}')\n\t\t\t}`\n\t\t} else\n\t\t\tfor (const name of cookieMeta.sign) {\n\t\t\t\tencodeCookie += `if(_setCookie['${name}']?.value) { c.set.cookie['${name}'].value = await signCookie(_setCookie['${name}'].value, '${secret}') }\\n`\n\t\t\t}\n\n\t\tencodeCookie += '}\\n'\n\t}\n\n\tconst normalize = app.config.normalize\n\n\tconst { composeValidation, composeResponseValidation } =\n\t\tcomposeValidationFactory(hasErrorHandler, {\n\t\t\tnormalize\n\t\t})\n\n\tif (hasHeaders) {\n\t\t// This function is Bun specific\n\t\t// @ts-ignore\n\t\tfnLiteral += headersHasToJSON\n\t\t\t? `c.headers = c.request.headers.toJSON()\\n`\n\t\t\t: `c.headers = {}\n for (const [key, value] of c.request.headers.entries())\n\t\t\t\t\tc.headers[key] = value\n\t\t\t\t`\n\t}\n\n\tif (hasCookie) {\n\t\tconst get = (name: keyof CookieOptions, defaultValue?: unknown) => {\n\t\t\t// @ts-ignore\n\t\t\tconst value = cookieMeta?.[name] ?? defaultValue\n\t\t\tif (!value)\n\t\t\t\treturn typeof defaultValue === 'string'\n\t\t\t\t\t? `${name}: \"${defaultValue}\",`\n\t\t\t\t\t: `${name}: ${defaultValue},`\n\n\t\t\tif (typeof value === 'string') return `${name}: '${value}',`\n\t\t\tif (value instanceof Date)\n\t\t\t\treturn `${name}: new Date(${value.getTime()}),`\n\n\t\t\treturn `${name}: ${value},`\n\t\t}\n\n\t\tconst options = cookieMeta\n\t\t\t? `{\n\t\t\tsecrets: ${\n\t\t\t\tcookieMeta.secrets !== undefined\n\t\t\t\t\t? typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t\t? `'${cookieMeta.secrets}'`\n\t\t\t\t\t\t: '[' +\n\t\t\t\t\t\t cookieMeta.secrets.reduce(\n\t\t\t\t\t\t\t\t(a, b) => a + `'${b}',`,\n\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t ) +\n\t\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\tsign: ${\n\t\t\t\tcookieMeta.sign === true\n\t\t\t\t\t? true\n\t\t\t\t\t: cookieMeta.sign !== undefined\n\t\t\t\t\t? '[' +\n\t\t\t\t\t cookieMeta.sign.reduce((a, b) => a + `'${b}',`, '') +\n\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\t${get('domain')}\n\t\t\t${get('expires')}\n\t\t\t${get('httpOnly')}\n\t\t\t${get('maxAge')}\n\t\t\t${get('path', '/')}\n\t\t\t${get('priority')}\n\t\t\t${get('sameSite')}\n\t\t\t${get('secure')}\n\t\t}`\n\t\t\t: 'undefined'\n\n\t\tif (hasHeaders)\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${options})\\n`\n\t\telse\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${options})\\n`\n\t}\n\n\tif (hasQuery) {\n\t\tlet destructured = [] as string[]\n\n\t\t// @ts-ignore\n\t\tif (validator.query && validator.query.schema.type === 'object') {\n\t\t\t// @ts-ignore\n\t\t\tdestructured = Object.keys(validator.query.schema.properties)\n\t\t} else\n\t\t\tfor (const query of inference.queries)\n\t\t\t\tif (destructured.indexOf(query) === -1) destructured.push(query)\n\n\t\tif (\n\t\t\tapp.config.forceDynamicQuery === true ||\n\t\t\tinference.unknownQueries === true ||\n\t\t\t!destructured.length\n\t\t) {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tc.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\\\+/g, ' '))\n\n\t\t\t\tfor(const key of Object.keys(c.query))\n\t\t\t\t\tc.query[key] = decodeURIComponent(c.query[key])\n\t\t\t} else c.query = {}`\n\t\t} else {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tlet url = c.request.url.slice(c.qi).replace(/\\\\+/g, ' ')\n\n\t\t\t\t${destructured\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(name, index) => `\n\t\t\t\t\t\t${index === 0 ? 'let' : ''} memory = url.indexOf('&${name}=')\n\t\t\t\t\t\tif(memory === -1) memory = url.indexOf('?${name}=')\n\t\t\t\t\t\tlet a${index}\n\n\t\t\t\t\t\tif(memory !== -1) {\n\t\t\t\t\t\t\tconst start = memory + ${name.length + 2}\n\t\t\t\t\t\t\tmemory = url.indexOf('&', start)\n\n\t\t\t\t\t\t\tif(memory === -1) a${index} = decodeURIComponent(url.slice(start))\n\t\t\t\t\t\t\telse a${index} = decodeURIComponent(url.slice(start, memory))\n\t\t\t\t\t\t}`\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n')}\n\n\t\t\t\tc.query = {\n\t\t\t\t\t${destructured.map((name, index) => `'${name}': a${index}`).join(', ')}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tc.query = {}\n\t\t\t}`\n\t\t}\n\t}\n\n\tconst hasTraceSet = traceInference.set\n\tconst hasSet =\n\t\tinference.cookie ||\n\t\tinference.set ||\n\t\thasTraceSet ||\n\t\thasHeaders ||\n\t\t(isHandleFn && hasDefaultHeaders)\n\n\tif (hasTrace) fnLiteral += '\\nconst id = c.$$requestId\\n'\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet,\n\t\tcondition: traceConditions,\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tfnLiteral += hasErrorHandler ? '\\n try {\\n' : ''\n\n\tif (hasTraceSet) {\n\t\tfnLiteral += `\\nconst traceDone = Promise.all([`\n\t\tfor (let i = 0; i < hooks.trace.length; i++) {\n\t\t\tfnLiteral += `new Promise(r => { reporter.once(\\`res\\${id}.${i}\\`, r) }),`\n\t\t}\n\t\tfnLiteral += `])\\n`\n\t}\n\n\tconst isAsyncHandler = typeof handler === 'function' && isAsync(handler)\n\n\tconst maybeAsync =\n\t\thasCookie ||\n\t\thasBody ||\n\t\thasTraceSet ||\n\t\tisAsyncHandler ||\n\t\t!!hooks.mapResponse.length ||\n\t\thooks.parse.length > 0 ||\n\t\thooks.afterHandle.some(isAsync) ||\n\t\thooks.beforeHandle.some(isAsync) ||\n\t\thooks.transform.some(isAsync)\n\n\tconst endParse = report('parse', {\n\t\tunit: hooks.parse.length\n\t})\n\n\tif (hasBody) {\n\t\tconst type = getUnionedType(validator?.body)\n\n\t\tif (hooks.type && !Array.isArray(hooks.type)) {\n\t\t\tif (hooks.type) {\n\t\t\t\tswitch (hooks.type) {\n\t\t\t\t\tcase 'json':\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\tif (hasErrorHandler)\n\t\t\t\t\t\t\tfnLiteral += `const tempBody = await c.request.text()\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t\t}`\n\t\t\t\t\t\telse fnLiteral += `c.body = await c.request.json()`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text':\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.text()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'urlencoded':\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tfnLiteral += `c.body = parseQuery(await c.request.text())\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'arrayBuffer':\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.arrayBuffer()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'formdata':\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tfnLiteral += `c.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (hooks.parse.length) fnLiteral += '}}'\n\t\t} else {\n\t\t\tconst getAotParser = () => {\n\t\t\t\tif (hooks.parse.length && type && !Array.isArray(hooks.type)) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst schema = validator?.body?.schema\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof schema === 'object' &&\n\t\t\t\t\t\t(hasType('File', schema) || hasType('Files', schema))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn `c.body = {}\n\n\t\t\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t\t\t}`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst aotParse = getAotParser()\n\n\t\t\tif (aotParse) fnLiteral += aotParse\n\t\t\telse {\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t\tfnLiteral += hasHeaders\n\t\t\t\t\t? `let contentType = c.headers['content-type']`\n\t\t\t\t\t: `let contentType = c.request.headers.get('content-type')`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tif (contentType) {\n\t\t\t\t\tconst index = contentType.indexOf(';')\n\t\t\t\t\tif (index !== -1) contentType = contentType.substring(0, index)\\n`\n\n\t\t\t\tif (hooks.parse.length) {\n\t\t\t\t\tfnLiteral += `let used = false\\n`\n\n\t\t\t\t\tconst endReport = report('parse', {\n\t\t\t\t\t\tunit: hooks.parse.length\n\t\t\t\t\t})\n\n\t\t\t\t\tfor (let i = 0; i < hooks.parse.length; i++) {\n\t\t\t\t\t\tconst endUnit = report('parse.unit', {\n\t\t\t\t\t\t\tname: hooks.parse[i].fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tconst name = `bo${i}`\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `if(!used) {\\n`\n\n\t\t\t\t\t\tfnLiteral += `let ${name} = parse[${i}](c, contentType)\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} instanceof Promise) ${name} = await ${name}\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} !== undefined) { c.body = ${name}; used = true }\\n`\n\n\t\t\t\t\t\tendUnit()\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `}`\n\t\t\t\t\t}\n\n\t\t\t\t\tendReport()\n\t\t\t\t}\n\n\t\t\t\tif (hooks.parse.length) fnLiteral += `if (!used)`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tswitch (contentType) {\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t${\n\t\t\t\t\t\t\thasErrorHandler\n\t\t\t\t\t\t\t\t? `\n\t\t\t\t\t\tconst tempBody = await c.request.text()\n\t\t\t\t\t\t\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t: `c.body = await c.request.json()\\n`\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tc.body = await c.request.text()\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tc.body = parseQuery(await c.request.text())\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tc.body = await c.request.arrayBuffer();\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tc.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\\n`\n\n\t\t\t\tfnLiteral += '}\\n'\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += '\\n'\n\t}\n\n\tendParse()\n\n\tif (hooks?.transform) {\n\t\tconst endTransform = report('transform', {\n\t\t\tunit: hooks.transform.length\n\t\t})\n\n\t\tif (hooks.transform.length) fnLiteral += '\\nlet transformed\\n'\n\n\t\tfor (let i = 0; i < hooks.transform.length; i++) {\n\t\t\tconst transform = hooks.transform[i]\n\n\t\t\tconst endUnit = report('transform.unit', {\n\t\t\t\tname: transform.fn.name\n\t\t\t})\n\n\t\t\tfnLiteral += isAsync(transform)\n\t\t\t\t? `transformed = await transform[${i}](c)\\n`\n\t\t\t\t: `transformed = transform[${i}](c)\\n`\n\n\t\t\tfnLiteral += `if(transformed?.[ELYSIA_RESPONSE])\n\t\t\t\tthrow transformed\n\t\t\telse\n\t\t\t\tObject.assign(c, transformed)\\n`\n\n\t\t\tendUnit()\n\t\t}\n\n\t\tendTransform()\n\t}\n\n\tif (validator) {\n\t\tfnLiteral += '\\n'\n\n\t\tif (validator.headers) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.headers.params))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.headers.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.headers['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(headers.Check(c.headers) === false) {\n\t\t\t\t${composeValidation('headers')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.headers.schema))\n\t\t\t\tfnLiteral += `\\nc.headers = headers.Decode(c.headers)\\n`\n\t\t}\n\n\t\tif (validator.params) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.params.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.params.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.params['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(params.Check(c.params) === false) {\n\t\t\t\t${composeValidation('params')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.params.schema))\n\t\t\t\tfnLiteral += `\\nc.params = params.Decode(c.params)\\n`\n\t\t}\n\n\t\tif (validator.query) {\n\t\t\tif (normalize) fnLiteral += 'c.query = query.Clean(c.query);\\n'\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.query.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.query.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed) fnLiteral += `c.query['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(query.Check(c.query) === false) {\n\t\t\t\t${composeValidation('query')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.query.schema))\n\t\t\t\t// Decode doesn't work with Object.create(null)\n\t\t\t\tfnLiteral += `\\nc.query = query.Decode(Object.assign({}, c.query))\\n`\n\t\t}\n\n\t\tif (validator.body) {\n\t\t\tif (normalize) fnLiteral += 'c.body = body.Clean(c.body);\\n'\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.body.schema))\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n \t\t\t\tc.body = Object.assign(${JSON.stringify(\n\t\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tvalidator.body.schema,\n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t) ?? {}\n\t\t\t\t\t)}, c.body)\n\n \t\t\t\tif(body.Check(c.query) === false) {\n \t\t\t\t${composeValidation('body')}\n \t\t\t}\n }`\n\t\t\telse\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n\t\t\t${composeValidation('body')}\n\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.body.schema))\n\t\t\t\tfnLiteral += `\\nc.body = body.Decode(c.body)\\n`\n\t\t}\n\n\t\t// @ts-ignore\n\t\tif (isNotEmpty(cookieValidator?.schema.properties ?? {})) {\n\t\t\tfnLiteral += `const cookieValue = {}\n \t\t\tfor(const [key, value] of Object.entries(c.cookie))\n \t\t\t\tcookieValue[key] = value.value\\n`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', cookieValidator.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tcookieValidator.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tfnLiteral += `cookieValue['${key}'] = ${\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: value\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(cookie.Check(cookieValue) === false) {\n\t\t\t\t${composeValidation('cookie', 'cookieValue')}\n\t\t\t}`\n\n\t\t\t// // @ts-ignore\n\t\t\t// if (hasTransform(validator.cookie.schema))\n\t\t\t// \tfnLiteral += `\\nc.cookie = params.Decode(c.cookie)\\n`\n\t\t}\n\t}\n\n\tif (hooks?.beforeHandle) {\n\t\tconst endBeforeHandle = report('beforeHandle', {\n\t\t\tunit: hooks.beforeHandle.length\n\t\t})\n\n\t\tlet hasResolve = false\n\n\t\tfor (let i = 0; i < hooks.beforeHandle.length; i++) {\n\t\t\tconst beforeHandle = hooks.beforeHandle[i]\n\n\t\t\tconst endUnit = report('beforeHandle.unit', {\n\t\t\t\tname: beforeHandle.fn.name\n\t\t\t})\n\n\t\t\tconst returning = hasReturn(beforeHandle.fn.toString())\n\n\t\t\tconst isResolver = beforeHandle.subType === 'resolve'\n\n\t\t\tif (isResolver) {\n\t\t\t\tif (!hasResolve) {\n\t\t\t\t\thasResolve = true\n\t\t\t\t\tfnLiteral += '\\nlet resolved\\n'\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `resolved = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `resolved = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tfnLiteral += `if(resolved[ELYSIA_RESPONSE])\n\t\t\t\t\t\tthrow resolved\n\t\t\t\t\telse\n\t\t\t\t\t\tObject.assign(c, resolved)\\n`\n\t\t\t} else if (!returning) {\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += `Object.assign(c, be);`\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `be = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `be = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(be !== undefined) {\\n`\n\t\t\t\tendBeforeHandle()\n\t\t\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\t\t\tunit: hooks.transform.length\n\t\t\t\t})\n\t\t\t\tif (hooks.afterHandle) {\n\t\t\t\t\treport('handle', {\n\t\t\t\t\t\tname: isHandleFn\n\t\t\t\t\t\t\t? (handler as Function).name\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t})()\n\n\t\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\t\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\t\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\t\t\t\tname: hook.fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tfnLiteral += `c.response = be\\n`\n\n\t\t\t\t\t\tif (!returning) {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `await afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t\t\t: `afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\t\t\t\tfnLiteral += `if(af !== undefined) { c.response = be = af }\\n`\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tendUnit()\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tendAfterHandle()\n\n\t\t\t\tif (validator.response)\n\t\t\t\t\tfnLiteral += composeResponseValidation('be')\n\n\t\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\t\tfnLiteral += `c.response = be`\n\n\t\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\t\t\t\tif(mr !== undefined) c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += encodeCookie\n\t\t\t\tfnLiteral += `return mapEarlyResponse(be, c.set, c.request)}\\n`\n\t\t\t}\n\t\t}\n\n\t\tendBeforeHandle()\n\t}\n\n\tif (hooks?.afterHandle.length) {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (hooks.afterHandle.length)\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = c.response = await ${handle};\\n`\n\t\t\t\t: `let r = c.response = ${handle};\\n`\n\t\telse\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\tendHandle()\n\n\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\tunit: hooks.afterHandle.length\n\t\t})\n\n\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\tname: hook.fn.name\n\t\t\t})\n\n\t\t\tif (!returning) {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tif (validator.response) {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += composeResponseValidation('af')\n\n\t\t\t\t\tfnLiteral += `c.response = af }`\n\t\t\t\t} else {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += `c.response = af}\\n`\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tendAfterHandle()\n\n\t\tfnLiteral += `r = c.response\\n`\n\n\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\tfnLiteral += encodeCookie\n\n\t\tif (hooks.mapResponse.length) {\n\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\tfnLiteral += `\\nmr = onMapResponse[${i}](c)\n\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\tif(mr !== undefined) c.response = mr\\n`\n\t\t\t}\n\t\t}\n\n\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t} else {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (validator.response || hooks.mapResponse.length) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) { \n\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else if (traceConditions.handle || hasCookie) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else {\n\t\t\tendHandle()\n\n\t\t\tconst handled = isAsyncHandler ? `await ${handle}` : handle\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(${handled}, c.set, c.request)\\n`\n\t\t\telse\n\t\t\t\tfnLiteral += `return mapCompactResponse(${handled}, c.request)\\n`\n\t\t}\n\t}\n\n\tif (hasErrorHandler || handleResponse) {\n\t\tfnLiteral += `\\n} catch(error) {`\n\t\tif (!maybeAsync) fnLiteral += `return (async () => {`\n\n\t\tfnLiteral += `const set = c.set\\nif (!set.status || set.status < 300) set.status = error?.status || 500\\n`\n\n\t\tconst endError = report('error', {\n\t\t\tunit: hooks.error.length\n\t\t})\n\n\t\tif (hooks.error.length) {\n\t\t\tfnLiteral += `\n\t\t\t\tc.error = error\n\t\t\t\tc.code = error.code ?? error[ERROR_CODE] ?? \"UNKNOWN\"\n\t\t\t`\n\n\t\t\tfor (let i = 0; i < hooks.error.length; i++) {\n\t\t\t\tconst name = `er${i}`\n\t\t\t\tconst endUnit = report('error.unit', {\n\t\t\t\t\tname: hooks.error[i].fn.name\n\t\t\t\t})\n\n\t\t\t\tfnLiteral += `\\nlet ${name} = handleErrors[${i}](c)\\n`\n\n\t\t\t\tif (isAsync(hooks.error[i]))\n\t\t\t\t\tfnLiteral += `if (${name} instanceof Promise) ${name} = await ${name}\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `${name} = mapEarlyResponse(${name}, set, c.request)\\n`\n\t\t\t\tfnLiteral += `if (${name}) {`\n\t\t\t\tfnLiteral += `return ${name} }\\n`\n\t\t\t}\n\t\t}\n\n\t\tendError()\n\n\t\tfnLiteral += `return handleError(c, error, true)\\n\\n`\n\n\t\tif (!maybeAsync) fnLiteral += '})()'\n\n\t\tfnLiteral += '}'\n\n\t\tif (handleResponse || hasTrace) {\n\t\t\tfnLiteral += ` finally { `\n\n\t\t\tconst endResponse = report('response', {\n\t\t\t\tunit: hooks.onResponse.length\n\t\t\t})\n\n\t\t\tfnLiteral += handleResponse\n\n\t\t\tendResponse()\n\n\t\t\tfnLiteral += `}`\n\t\t}\n\t}\n\n\tfnLiteral = `const {\n\t\thandler,\n\t\thandleError,\n\t\thooks: {\n\t\t\ttransform,\n\t\t\tresolve,\n\t\t\tbeforeHandle,\n\t\t\tafterHandle,\n\t\t\tmapResponse: onMapResponse,\n\t\t\tparse,\n\t\t\terror: handleErrors,\n\t\t\tonResponse\n\t\t},\n\t\tvalidator: {\n\t\t\tbody,\n\t\t\theaders,\n\t\t\tparams,\n\t\t\tquery,\n\t\t\tresponse,\n\t\t\tcookie\n\t\t},\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema,\n\t\tdefinitions,\n\t\tERROR_CODE,\n\t\tgetReporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t} = hooks\n\n\t${\n\t\thooks.onResponse.length\n\t\t\t? `const ${hooks.onResponse\n\t\t\t\t\t.map((x, i) => `res${i} = onResponse[${i}]`)\n\t\t\t\t\t.join(',')}`\n\t\t\t: ''\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function handle(c) {\n\t\t${hooks.beforeHandle.length ? 'let be' : ''}\n\t\t${hooks.afterHandle.length ? 'let af' : ''}\n\t\t${hooks.mapResponse.length ? 'let mr' : ''}\n\n\t\t${allowMeta ? 'c.schema = schema; c.defs = definitions' : ''}\n\t\t${fnLiteral}\n\t}`\n\n\tconst createHandler = Function('hooks', fnLiteral)\n\n\treturn createHandler({\n\t\thandler,\n\t\thooks: lifeCycleToFn(hooks),\n\t\tvalidator,\n\t\t// @ts-expect-error\n\t\thandleError: app.handleError,\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema: app.router.history,\n\t\t// @ts-expect-error\n\t\tdefinitions: app.definitions.type,\n\t\tERROR_CODE,\n\t\t// @ts-expect-error\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const composeGeneralHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tconst inference = {\n\t\tevent: {\n\t\t\t// @ts-expect-error\n\t\t\t...app.inference.event,\n\t\t\t// @ts-expect-error\n\t\t\tqueries: [...app.inference.event.queries]\n\t\t},\n\t\t// @ts-expect-error\n\t\ttrace: { ...app.inference.trace }\n\t}\n\n\tlet decoratorsLiteral = ''\n\tlet fnLiteral = ''\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\n\t// @ts-ignore\n\tfor (const key of Object.keys(app.singleton.decorator))\n\t\tdecoratorsLiteral += `,${key}: app.singleton.decorator.${key}`\n\n\tconst router = app.router\n\tconst hasTrace = app.event.trace.length > 0\n\n\tlet findDynamicRoute = `\n\tconst route = router.find(request.method, path) ${\n\t\trouter.http.root.ALL ? '?? router.find(\"ALL\", path)' : ''\n\t}\n\n\tif (route === null)\n\t\treturn ${\n\t\t\tapp.event.error.length\n\t\t\t\t? `app.handleError(ctx, notFound)`\n\t\t\t\t: app.event.request.length\n\t\t\t\t? `new Response(error404Message, {\n\t\t\t\t\tstatus: ctx.set.status === 200 ? 404 : ctx.set.status,\n\t\t\t\t\theaders: ctx.set.headers\n\t\t\t\t})`\n\t\t\t\t: `error404.clone()`\n\t\t}\n\n\tctx.params = route.params\\n`\n\n\tconst shouldPrecompile =\n\t\tapp.config.precompile === true ||\n\t\t(typeof app.config.precompile === 'object' &&\n\t\t\tapp.config.precompile.compose === true)\n\n\tif (!shouldPrecompile)\n\t\tfindDynamicRoute += `\n\t\t\tif(route.store.composed)\n\t\t\t\treturn route.store.composed(ctx)\n\n\t\t\tif(route.store.compose)\n\t\t\t\treturn (route.store.compose())(ctx)`\n\telse findDynamicRoute += `return route.store(ctx)`\n\n\tfindDynamicRoute += '\\n'\n\n\tlet switchMap = ``\n\tfor (const [path, { code, all }] of Object.entries(router.static.http.map))\n\t\tswitchMap += `case '${path}':\\nswitch(request.method) {\\n${code}\\n${\n\t\t\tall ?? `default: break map`\n\t\t}}\\n\\n`\n\n\tconst maybeAsync = app.event.request.some(isAsync)\n\n\tconst init = `\\n\n\tconst url = request.url\n\tconst s = url.indexOf('/', 11)\n\tconst qi = url.indexOf('?', s + 1)\n\tlet path\n\tif(qi === -1)\n\t\tpath = url.substring(s)\n\telse \n\t\tpath = url.substring(s, qi)\\n`\n\n\tfnLiteral += `const {\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\trequestId,\n\t\tgetReporter,\n\t\thandleError,\n\t\terror\n\t} = data\n\n\tconst store = app.singleton.store\n\tconst staticRouter = app.router.static.http\n\tconst wsRouter = app.router.ws\n\tconst router = app.router.http\n\n\tconst notFound = new NotFoundError()\n\n\t${\n\t\tapp.event.request.length\n\t\t\t? `const onRequest = app.event.request.map(x => x.fn)`\n\t\t\t: ''\n\t}\n\t${router.static.http.variables}\n\t${\n\t\tapp.event.error.length\n\t\t\t? ''\n\t\t\t: `\n\tconst error404Message = notFound.message.toString()\n\tconst error404 = new Response(error404Message, { status: 404 });\n\t`\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function map(request) {\\n`\n\n\tif (app.event.request.length) fnLiteral += `let re`\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet: inference.trace.set,\n\t\tcondition: {\n\t\t\trequest: inference.trace.request\n\t\t},\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tif (app.event.request.length) {\n\t\tfnLiteral += `\n\t\t\t${hasTrace ? 'const id = +requestId.value++' : ''}\n\n\t\t\tconst ctx = {\n\t\t\t\trequest,\n\t\t\t\tstore,\n\t\t\t\tset: {\n\t\t\t\t\theaders: ${\n\t\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t\t: '{}'\n\t\t\t\t\t},\n\t\t\t\t\tstatus: 200\n\t\t\t\t},\n\t\t\t\terror\n\t\t\t\t${hasTrace ? ',$$requestId: +id' : ''}\n\t\t\t\t${decoratorsLiteral}\n\t\t\t}\n\t\t`\n\n\t\tconst endReport = report('request', {\n\t\t\tattribute: 'ctx',\n\t\t\tunit: app.event.request.length\n\t\t})\n\n\t\tfnLiteral += `\\n try {\\n`\n\n\t\tfor (let i = 0; i < app.event.request.length; i++) {\n\t\t\tconst hook = app.event.request[i]\n\t\t\tconst withReturn = hasReturn(hook.fn.toString())\n\t\t\tconst maybeAsync = isAsync(hook)\n\n\t\t\tconst endUnit = report('request.unit', {\n\t\t\t\tname: app.event.request[i].fn.name\n\t\t\t})\n\n\t\t\tif (withReturn) {\n\t\t\t\tfnLiteral += `re = mapEarlyResponse(\n\t\t\t\t\t${maybeAsync ? 'await' : ''} onRequest[${i}](ctx),\n\t\t\t\t\tctx.set,\n\t\t\t\t\trequest\n\t\t\t\t)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(re !== undefined) return re\\n`\n\t\t\t} else {\n\t\t\t\tfnLiteral += `${\n\t\t\t\t\tmaybeAsync ? 'await' : ''\n\t\t\t\t} onRequest[${i}](ctx)\\n`\n\t\t\t\tendUnit()\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += `} catch (error) {\n\t\t\treturn app.handleError(ctx, error)\n\t\t}`\n\n\t\tendReport()\n\n\t\tfnLiteral += init\n\t\tfnLiteral += `\\nctx.qi = qi\\n ctx.path = path\\n`\n\t} else {\n\t\tfnLiteral += init\n\t\tfnLiteral += `${hasTrace ? 'const id = +requestId.value++' : ''}\n\t\tconst ctx = {\n\t\t\trequest,\n\t\t\tstore,\n\t\t\tqi,\n\t\t\tpath,\n\t\t\tset: {\n\t\t\t\theaders: ${\n\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t: '{}'\n\t\t\t\t},\n\t\t\t\tstatus: 200\n\t\t\t},\n\t\t\terror\n\t\t\t${hasTrace ? ',$$requestId: id' : ''}\n\t\t\t${decoratorsLiteral}\n\t\t}`\n\n\t\treport('request', {\n\t\t\tunit: app.event.request.length,\n\t\t\tattribute:\n\t\t\t\tinference.trace.context ||\n\t\t\t\tinference.trace.store ||\n\t\t\t\tinference.trace.set\n\t\t\t\t\t? 'ctx'\n\t\t\t\t\t: ''\n\t\t})()\n\t}\n\n\tconst wsPaths = app.router.static.ws\n\tconst wsRouter = app.router.ws\n\n\tif (Object.keys(wsPaths).length || wsRouter.history.length) {\n\t\tfnLiteral += `\n\t\t\tif(request.method === 'GET') {\n\t\t\t\tswitch(path) {`\n\n\t\tfor (const [path, index] of Object.entries(wsPaths)) {\n\t\t\tfnLiteral += `\n\t\t\t\t\tcase '${path}':\n\t\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket')\n\t\t\t\t\t\t\treturn st${index}(ctx)\n\n\t\t\t\t\t\tbreak`\n\t\t}\n\n\t\tfnLiteral += `\n\t\t\t\tdefault:\n\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket') {\n\t\t\t\t\t\tconst route = wsRouter.find('ws', path)\n\n\t\t\t\t\t\tif(route) {\n\t\t\t\t\t\t\tctx.params = route.params\n\n\t\t\t\t\t\t\treturn route.store(ctx)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\\n`\n\t}\n\n\tfnLiteral += `\n\t\tmap: switch(path) {\n\t\t\t${switchMap}\n\n\t\t\tdefault:\n\t\t\t\tbreak\n\t\t}\n\n\t\t${findDynamicRoute}\n\t}`\n\n\tconst handleError = composeErrorHandler(app) as any\n\n\t// @ts-ignore\n\tapp.handleError = handleError\n\n\treturn Function(\n\t\t'data',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\t// @ts-ignore\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\thandleError,\n\t\terror\n\t})\n}\n\nexport const composeErrorHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tlet fnLiteral = `const {\n\t\tapp: { event: { error: onErrorContainer, onResponse: resContainer } },\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t} = inject\n\n\tconst onError = onErrorContainer.map(x => x.fn)\n\tconst res = resContainer.map(x => x.fn)\n\n\treturn ${\n\t\tapp.event.error.find(isAsync) ? 'async' : ''\n\t} function(context, error, skipGlobal) {\n\t\tlet r\n\n\t\tconst { set } = context\n\n\t\tcontext.code = error.code\n\t\tcontext.error = error\n\n\t\tif(ELYSIA_RESPONSE in error) {\n\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\terror.message = error.response\n\t\t}\\n`\n\n\tfor (let i = 0; i < app.event.error.length; i++) {\n\t\tconst handler = app.event.error[i]\n\n\t\tconst response = `${\n\t\t\tisAsync(handler) ? 'await ' : ''\n\t\t}onError[${i}](context)`\n\n\t\tfnLiteral += '\\nif(skipGlobal !== true) {\\n'\n\n\t\tif (hasReturn(handler.fn.toString()))\n\t\t\tfnLiteral += `r = ${response}; if(r !== undefined) {\n\t\t\t\tif(r instanceof Response) return r\n\n\t\t\t\tif(r[ELYSIA_RESPONSE]) {\n\t\t\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\t\t\terror.message = error.response\n\t\t\t\t}\n\t\t\n\t\t\t\tif(set.status === 200) set.status = error.status\n\t\t\t\treturn mapResponse(r, set, context.request)\n\t\t\t}\\n`\n\t\telse fnLiteral += response + '\\n'\n\n\t\tfnLiteral += '\\n}\\n'\n\t}\n\n\tfnLiteral += `if(error.constructor.name === \"ValidationError\" || error.constructor.name === \"TransformDecodeError\") {\n\t\tset.status = error.status ?? 422\n\t\treturn new Response(\n\t\t\terror.message,\n\t\t\t{ \n\t\t\t\theaders: Object.assign(\n\t\t\t\t\t{ 'content-type': 'application/json'}, \n\t\t\t\t\tset.headers\n\t\t\t\t), \n\t\t\t\tstatus: set.status\n\t\t\t}\n\t\t)\n\t} else {\n\t\tif(error.code && typeof error.status === \"number\")\n\t\t\treturn new Response(\n\t\t\t\terror.message,\n\t\t\t\t{ headers: set.headers, status: error.status }\n\t\t\t)\n\n\t\treturn mapResponse(error, set, context.request)\n\t}\n}`\n\n\treturn Function(\n\t\t'inject',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const jitRoute = (\n\tindex: number\n) => `if(stc${index}) return stc${index}(ctx)\nif(st${index}.compose) return (stc${index} = st${index}.compose())(ctx)\n\nreturn st${index}(ctx)`\n",
26
+ "import { type Elysia } from '.'\n\nimport { Value } from '@sinclair/typebox/value'\nimport { TypeCheck } from '@sinclair/typebox/compiler'\nimport type { TAnySchema } from '@sinclair/typebox'\n\nimport { parse as parseQuery } from 'fast-querystring'\n\n// @ts-expect-error\nimport decodeURIComponent from 'fast-decode-uri-component'\n\nimport { getCookieValidator, lifeCycleToFn, signCookie } from './utils'\nimport { ParseError, error } from './error'\n\nimport {\n\tmapEarlyResponse,\n\tmapResponse,\n\tmapCompactResponse,\n\tisNotEmpty\n} from './handler'\nimport {\n\tNotFoundError,\n\tValidationError,\n\tInternalServerError,\n\tERROR_CODE,\n\tELYSIA_RESPONSE\n} from './error'\n\nimport { Sucrose, sucrose } from './sucrose'\nimport { parseCookie, type CookieOptions } from './cookies'\n\nimport type {\n\tComposedHandler,\n\tHandler,\n\tHookContainer,\n\tLifeCycleStore,\n\tSchemaValidator,\n\tTraceEvent\n} from './types'\n\nconst headersHasToJSON = (new Headers() as Headers).toJSON\nconst requestId = { value: 0 }\n\nconst createReport = ({\n\thasTrace,\n\thasTraceSet = false,\n\taddFn,\n\tcondition = {}\n}: {\n\thasTrace: boolean | number\n\thasTraceSet?: boolean\n\taddFn(string: string): void\n\tcondition: Partial<Record<TraceEvent, boolean>>\n}) => {\n\tif (hasTrace) {\n\t\taddFn(`\\nconst reporter = getReporter()\\n`)\n\n\t\treturn (\n\t\t\tevent: TraceEvent,\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\tattribute = '',\n\t\t\t\tunit = 0\n\t\t\t}: {\n\t\t\t\tname?: string\n\t\t\t\tattribute?: string\n\t\t\t\tunit?: number\n\t\t\t} = {}\n\t\t) => {\n\t\t\tconst dotIndex = event.indexOf('.')\n\t\t\tconst isGroup = dotIndex === -1\n\n\t\t\tif (\n\t\t\t\tevent !== 'request' &&\n\t\t\t\tevent !== 'response' &&\n\t\t\t\t!condition[\n\t\t\t\t\t(isGroup\n\t\t\t\t\t\t? event\n\t\t\t\t\t\t: event.slice(0, dotIndex)) as keyof typeof condition\n\t\t\t\t]\n\t\t\t)\n\t\t\t\treturn () => {\n\t\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t\t}\n\n\t\t\tif (isGroup) name ||= event\n\t\t\telse name ||= 'anonymous'\n\n\t\t\taddFn(\n\t\t\t\t'\\n' +\n\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\tid,\n\t\t\t\t\tevent: '${event}',\n\t\t\t\t\ttype: 'begin',\n\t\t\t\t\tname: '${name}',\n\t\t\t\t\ttime: performance.now(),\n\t\t\t\t\t${isGroup ? `unit: ${unit},` : ''}\n\t\t\t\t\t${attribute}\n\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t'\\n'\n\t\t\t)\n\n\t\t\treturn () => {\n\t\t\t\taddFn(\n\t\t\t\t\t'\\n' +\n\t\t\t\t\t\t`reporter.emit('event', {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tevent: '${event}',\n\t\t\t\t\t\t\ttype: 'end',\n\t\t\t\t\t\t\ttime: performance.now()\n\t\t\t\t\t\t})`.replace(/(\\t| |\\n)/g, '') +\n\t\t\t\t\t\t'\\n'\n\t\t\t\t)\n\n\t\t\t\tif (hasTraceSet && event === 'afterHandle')\n\t\t\t\t\taddFn(`\\nawait traceDone\\n`)\n\t\t\t}\n\t\t}\n\t} else {\n\t\treturn () => () => {}\n\t}\n}\n\nexport const hasReturn = (fnLiteral: string) => {\n\tconst parenthesisEnd = fnLiteral.indexOf(')')\n\n\t// Is direct arrow function return eg. () => 1\n\tif (\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 2) === 61 &&\n\t\tfnLiteral.charCodeAt(parenthesisEnd + 5) !== 123\n\t) {\n\t\treturn true\n\t}\n\n\treturn fnLiteral.includes('return')\n}\n\nconst composeValidationFactory = (\n\thasErrorHandler: boolean,\n\t{\n\t\tinjectResponse = '',\n\t\tnormalize = false\n\t}: {\n\t\tinjectResponse?: string\n\t\tnormalize?: boolean\n\t} = {}\n) => ({\n\tcomposeValidation: (type: string, value = `c.${type}`) =>\n\t\thasErrorHandler\n\t\t\t? `c.set.status = 422; throw new ValidationError('${type}', ${type}, ${value})`\n\t\t\t: `c.set.status = 422; return new ValidationError('${type}', ${type}, ${value}).toResponse(c.set.headers)`,\n\tcomposeResponseValidation: (name = 'r') => {\n\t\tconst returnError = hasErrorHandler\n\t\t\t? `throw new ValidationError('response', response[c.set.status], ${name})`\n\t\t\t: `return new ValidationError('response', response[c.set.status], ${name}).toResponse(c.set.headers)`\n\n\t\tlet code = '\\n' + injectResponse + '\\n'\n\n\t\tcode += `let er\n\t\t\n\t\tif(${name} && typeof ${name} === \"object\" && ELYSIA_RESPONSE in ${name})\n\t\t\ter = ${name}[ELYSIA_RESPONSE]\\n`\n\n\t\tif (normalize)\n\t\t\tcode += `\n\t\t\tif(!er && response[c.set.status]?.Clean)\n\t\t\t\t${name} = response[c.set.status]?.Clean(${name})\n\t\t\telse if(response[er]?.Clean)\n\t\t\t\t${name}.response = response[er]?.Clean(${name}.response)`\n\n\t\tcode += `\n\t\t\tif(er) {\n\t\t\t\tif(!(${name} instanceof Response) && response[er]?.Check(${name}.response) === false) {\n\t\t\t\t\tif(!(response instanceof Error)) {\n\t\t\t\t\t\tc.set.status = ${name}[ELYSIA_RESPONSE]\n\n\t\t\t\t\t\t${returnError}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if(!(${name} instanceof Response) && response[c.set.status]?.Check(${name}) === false) {\n\t\t\t\tif(!(response instanceof Error))\n\t\t\t\t\t${returnError}\n\t\t\t}\\n`\n\n\t\treturn code\n\t}\n})\n\nconst KindSymbol = Symbol.for('TypeBox.Kind')\n\nexport const hasType = (type: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (KindSymbol in schema && schema[KindSymbol] === type) return true\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasType(type, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasType(type, property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tif (KindSymbol in property && property[KindSymbol] === type)\n\t\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tschema.properties &&\n\t\tKindSymbol in schema.properties &&\n\t\tschema.properties[KindSymbol] === type\n\t)\n}\n\nexport const hasProperty = (expectedProperty: string, schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object') {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\n\t\tif (!properties) return false\n\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (expectedProperty in property) return true\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasProperty(expectedProperty, property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++) {\n\t\t\t\t\tif (hasProperty(expectedProperty, property.anyOf[i]))\n\t\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn expectedProperty in schema\n}\n\nconst TransformSymbol = Symbol.for('TypeBox.Transform')\n\nexport const hasTransform = (schema: TAnySchema) => {\n\tif (!schema) return\n\n\tif (schema.type === 'object' && schema.properties) {\n\t\tconst properties = schema.properties as Record<string, TAnySchema>\n\t\tfor (const key of Object.keys(properties)) {\n\t\t\tconst property = properties[key]\n\n\t\t\tif (property.type === 'object') {\n\t\t\t\tif (hasTransform(property)) return true\n\t\t\t} else if (property.anyOf) {\n\t\t\t\tfor (let i = 0; i < property.anyOf.length; i++)\n\t\t\t\t\tif (hasTransform(property.anyOf[i])) return true\n\t\t\t}\n\n\t\t\tconst hasTransformSymbol = TransformSymbol in property\n\t\t\tif (hasTransformSymbol) return true\n\t\t}\n\n\t\treturn false\n\t}\n\n\treturn (\n\t\tTransformSymbol in schema ||\n\t\t(schema.properties && TransformSymbol in schema.properties)\n\t)\n}\n\n/**\n * This function will return the type of unioned if all unioned type is the same.\n * It's intent to use for content-type mapping only\n *\n * ```ts\n * t.Union([\n * t.Object({\n * password: t.String()\n * }),\n * t.Object({\n * token: t.String()\n * })\n * ])\n * ```\n */\nconst getUnionedType = (validator: TypeCheck<any> | undefined) => {\n\tif (!validator) return\n\n\t// @ts-ignore\n\tconst schema = validator?.schema\n\n\tif (schema && 'anyOf' in schema) {\n\t\tlet foundDifference = false\n\t\tconst type: string = schema.anyOf[0].type\n\n\t\tfor (const validator of schema.anyOf as { type: string }[]) {\n\t\t\tif (validator.type !== type) {\n\t\t\t\tfoundDifference = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (!foundDifference) return type\n\t}\n\n\t// @ts-ignore\n\treturn validator.schema?.type\n}\n\nconst matchFnReturn = /(?:return|=>) \\S+\\(/g\n\nexport const isAsync = (v: Function | HookContainer) => {\n\tconst fn = 'fn' in v ? v.fn : v\n\n\tif (fn.constructor.name === 'AsyncFunction') return true\n\n\tconst literal = fn.toString()\n\tif (literal.includes('=> response.clone(')) return false\n\n\treturn !!literal.match(matchFnReturn)\n}\n\nexport const composeHandler = ({\n\tapp,\n\tpath,\n\tmethod,\n\tlocalHook,\n\thooks,\n\tvalidator,\n\thandler,\n\tallowMeta = false,\n\tappInference: { event: eventInference, trace: traceInference }\n}: {\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n\tpath: string\n\tmethod: string\n\thooks: LifeCycleStore\n\tlocalHook: LifeCycleStore\n\tvalidator: SchemaValidator\n\thandler: unknown | Handler<any, any>\n\tallowMeta?: boolean\n\tappInference: {\n\t\tevent: Sucrose.Inference\n\t\ttrace: Sucrose.TraceInference\n\t}\n}): ComposedHandler => {\n\tconst isHandleFn = typeof handler === 'function'\n\n\tif (!isHandleFn)\n\t\thandler = mapResponse(handler, {\n\t\t\t// @ts-expect-error private property\n\t\t\theaders: app.setHeaders ?? {}\n\t\t})\n\n\tconst hasErrorHandler =\n\t\t(app.config.forceErrorEncapsulation &&\n\t\t\t(isHandleFn ||\n\t\t\t\thooks.afterHandle.length > 0 ||\n\t\t\t\thooks.beforeHandle.length > 0 ||\n\t\t\t\thooks.transform.length > 0)) ||\n\t\thooks.error.length > 0 ||\n\t\tapp.event.error.length > 0 ||\n\t\ttypeof Bun === 'undefined' ||\n\t\thooks.onResponse.length > 0 ||\n\t\thooks.onResponse.length > 0 ||\n\t\t!!hooks.trace.length\n\n\tconst handle = isHandleFn ? `handler(c)` : `handler`\n\tconst handleResponse = hooks.onResponse.length\n\t\t? `\\n;(async () => {${hooks.onResponse\n\t\t\t\t.map((_, i) => `await res${i}(c)`)\n\t\t\t\t.join(';')}})();\\n`\n\t\t: ''\n\n\tconst traceConditions: Record<\n\t\tExclude<TraceEvent, `${string}.unit` | 'request' | 'response' | 'exit'>,\n\t\tboolean\n\t> = traceInference\n\n\tconst hasTrace = hooks.trace.length > 0\n\tlet fnLiteral = ''\n\n\tconst inference = sucrose(\n\t\tObject.assign(localHook, {\n\t\t\thandler: handler as any\n\t\t}),\n\t\teventInference\n\t)\n\n\tconst hasQuery = inference.query || !!validator.query\n\n\tconst hasBody =\n\t\tmethod !== '$INTERNALWS' &&\n\t\tmethod !== 'GET' &&\n\t\tmethod !== 'HEAD' &&\n\t\thooks.type !== 'none' &&\n\t\t(inference.body || !!validator.body)\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\tconst hasDefaultHeaders =\n\t\tdefaultHeaders && !!Object.keys(defaultHeaders).length\n\n\t// ? defaultHeaders doesn't imply that user will use headers in handler\n\tconst hasHeaders = inference.headers || validator.headers\n\tconst hasCookie = inference.cookie || !!validator.cookie\n\n\tconst cookieValidator = hasCookie\n\t\t? getCookieValidator({\n\t\t\t\tvalidator: validator.cookie as any,\n\t\t\t\tdefaultConfig: app.config.cookie,\n\t\t\t\tdynamic: !!app.config.aot,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tconfig: validator.cookie?.config ?? {},\n\t\t\t\t// @ts-expect-error\n\t\t\t\tmodels: app.definitions.type\n\t\t })\n\t\t: undefined\n\n\t// @ts-ignore private property\n\tconst cookieMeta = cookieValidator?.config as {\n\t\tsecrets?: string | string[]\n\t\tsign: string[] | true\n\t\tproperties: { [x: string]: Object }\n\t}\n\n\tlet encodeCookie = ''\n\n\tif (cookieMeta?.sign) {\n\t\tif (!cookieMeta.secrets)\n\t\t\tthrow new Error(\n\t\t\t\t`t.Cookie required secret which is not set in (${method}) ${path}.`\n\t\t\t)\n\n\t\tconst secret = !cookieMeta.secrets\n\t\t\t? undefined\n\t\t\t: typeof cookieMeta.secrets === 'string'\n\t\t\t? cookieMeta.secrets\n\t\t\t: cookieMeta.secrets[0]\n\n\t\tencodeCookie += `const _setCookie = c.set.cookie\n\t\tif(_setCookie) {`\n\n\t\tif (cookieMeta.sign === true) {\n\t\t\tencodeCookie += `for(const [key, cookie] of Object.entries(_setCookie)) {\n\t\t\t\tc.set.cookie[key].value = await signCookie(cookie.value, '${secret}')\n\t\t\t}`\n\t\t} else\n\t\t\tfor (const name of cookieMeta.sign) {\n\t\t\t\tencodeCookie += `if(_setCookie['${name}']?.value) { c.set.cookie['${name}'].value = await signCookie(_setCookie['${name}'].value, '${secret}') }\\n`\n\t\t\t}\n\n\t\tencodeCookie += '}\\n'\n\t}\n\n\tconst normalize = app.config.normalize\n\n\tconst { composeValidation, composeResponseValidation } =\n\t\tcomposeValidationFactory(hasErrorHandler, {\n\t\t\tnormalize\n\t\t})\n\n\tif (hasHeaders) {\n\t\t// This function is Bun specific\n\t\t// @ts-ignore\n\t\tfnLiteral += headersHasToJSON\n\t\t\t? `c.headers = c.request.headers.toJSON()\\n`\n\t\t\t: `c.headers = {}\n for (const [key, value] of c.request.headers.entries())\n\t\t\t\t\tc.headers[key] = value\n\t\t\t\t`\n\t}\n\n\tif (hasCookie) {\n\t\tconst get = (name: keyof CookieOptions, defaultValue?: unknown) => {\n\t\t\t// @ts-ignore\n\t\t\tconst value = cookieMeta?.[name] ?? defaultValue\n\t\t\tif (!value)\n\t\t\t\treturn typeof defaultValue === 'string'\n\t\t\t\t\t? `${name}: \"${defaultValue}\",`\n\t\t\t\t\t: `${name}: ${defaultValue},`\n\n\t\t\tif (typeof value === 'string') return `${name}: '${value}',`\n\t\t\tif (value instanceof Date)\n\t\t\t\treturn `${name}: new Date(${value.getTime()}),`\n\n\t\t\treturn `${name}: ${value},`\n\t\t}\n\n\t\tconst options = cookieMeta\n\t\t\t? `{\n\t\t\tsecrets: ${\n\t\t\t\tcookieMeta.secrets !== undefined\n\t\t\t\t\t? typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t\t? `'${cookieMeta.secrets}'`\n\t\t\t\t\t\t: '[' +\n\t\t\t\t\t\t cookieMeta.secrets.reduce(\n\t\t\t\t\t\t\t\t(a, b) => a + `'${b}',`,\n\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t ) +\n\t\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\tsign: ${\n\t\t\t\tcookieMeta.sign === true\n\t\t\t\t\t? true\n\t\t\t\t\t: cookieMeta.sign !== undefined\n\t\t\t\t\t? '[' +\n\t\t\t\t\t cookieMeta.sign.reduce((a, b) => a + `'${b}',`, '') +\n\t\t\t\t\t ']'\n\t\t\t\t\t: 'undefined'\n\t\t\t},\n\t\t\t${get('domain')}\n\t\t\t${get('expires')}\n\t\t\t${get('httpOnly')}\n\t\t\t${get('maxAge')}\n\t\t\t${get('path', '/')}\n\t\t\t${get('priority')}\n\t\t\t${get('sameSite')}\n\t\t\t${get('secure')}\n\t\t}`\n\t\t\t: 'undefined'\n\n\t\tif (hasHeaders)\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${options})\\n`\n\t\telse\n\t\t\tfnLiteral += `\\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${options})\\n`\n\t}\n\n\tif (hasQuery) {\n\t\tlet destructured = [] as string[]\n\n\t\t// @ts-ignore\n\t\tif (validator.query && validator.query.schema.type === 'object') {\n\t\t\t// @ts-ignore\n\t\t\tdestructured = Object.keys(validator.query.schema.properties)\n\t\t} else\n\t\t\tfor (const query of inference.queries)\n\t\t\t\tif (destructured.indexOf(query) === -1) destructured.push(query)\n\n\t\tif (\n\t\t\tapp.config.forceDynamicQuery === true ||\n\t\t\tinference.unknownQueries === true ||\n\t\t\t!destructured.length\n\t\t) {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tc.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\\\+/g, ' '))\n\n\t\t\t\tfor(const key of Object.keys(c.query))\n\t\t\t\t\tc.query[key] = decodeURIComponent(c.query[key])\n\t\t\t} else c.query = {}`\n\t\t} else {\n\t\t\tfnLiteral += `if(c.qi !== -1) {\n\t\t\t\tlet url = c.request.url.slice(c.qi).replace(/\\\\+/g, ' ')\n\n\t\t\t\t${destructured\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(name, index) => `\n\t\t\t\t\t\t${index === 0 ? 'let' : ''} memory = url.indexOf('&${name}=')\n\t\t\t\t\t\tif(memory === -1) memory = url.indexOf('?${name}=')\n\t\t\t\t\t\tlet a${index}\n\n\t\t\t\t\t\tif(memory !== -1) {\n\t\t\t\t\t\t\tconst start = memory + ${name.length + 2}\n\t\t\t\t\t\t\tmemory = url.indexOf('&', start)\n\n\t\t\t\t\t\t\tif(memory === -1) a${index} = decodeURIComponent(url.slice(start))\n\t\t\t\t\t\t\telse a${index} = decodeURIComponent(url.slice(start, memory))\n\t\t\t\t\t\t}`\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n')}\n\n\t\t\t\tc.query = {\n\t\t\t\t\t${destructured.map((name, index) => `'${name}': a${index}`).join(', ')}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tc.query = {}\n\t\t\t}`\n\t\t}\n\t}\n\n\tconst hasTraceSet = traceInference.set\n\tconst hasSet =\n\t\tinference.cookie ||\n\t\tinference.set ||\n\t\thasTraceSet ||\n\t\thasHeaders ||\n\t\t(isHandleFn && hasDefaultHeaders)\n\n\tif (hasTrace) fnLiteral += '\\nconst id = c.$$requestId\\n'\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet,\n\t\tcondition: traceConditions,\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tfnLiteral += hasErrorHandler ? '\\n try {\\n' : ''\n\n\tif (hasTraceSet) {\n\t\tfnLiteral += `\\nconst traceDone = Promise.all([`\n\t\tfor (let i = 0; i < hooks.trace.length; i++) {\n\t\t\tfnLiteral += `new Promise(r => { reporter.once(\\`res\\${id}.${i}\\`, r) }),`\n\t\t}\n\t\tfnLiteral += `])\\n`\n\t}\n\n\tconst isAsyncHandler = typeof handler === 'function' && isAsync(handler)\n\n\tconst maybeAsync =\n\t\thasCookie ||\n\t\thasBody ||\n\t\thasTraceSet ||\n\t\tisAsyncHandler ||\n\t\t!!hooks.mapResponse.length ||\n\t\thooks.parse.length > 0 ||\n\t\thooks.afterHandle.some(isAsync) ||\n\t\thooks.beforeHandle.some(isAsync) ||\n\t\thooks.transform.some(isAsync)\n\n\tconst endParse = report('parse', {\n\t\tunit: hooks.parse.length\n\t})\n\n\tif (hasBody) {\n\t\tconst type = getUnionedType(validator?.body)\n\n\t\tif (hooks.type && !Array.isArray(hooks.type)) {\n\t\t\tif (hooks.type) {\n\t\t\t\tswitch (hooks.type) {\n\t\t\t\t\tcase 'json':\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\tif (hasErrorHandler)\n\t\t\t\t\t\t\tfnLiteral += `const tempBody = await c.request.text()\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t\t}`\n\t\t\t\t\t\telse fnLiteral += `c.body = await c.request.json()`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text':\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.text()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'urlencoded':\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tfnLiteral += `c.body = parseQuery(await c.request.text())\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'arrayBuffer':\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tfnLiteral += `c.body = await c.request.arrayBuffer()\\n`\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'formdata':\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tfnLiteral += `c.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (hooks.parse.length) fnLiteral += '}}'\n\t\t} else {\n\t\t\tconst getAotParser = () => {\n\t\t\t\tif (hooks.parse.length && type && !Array.isArray(hooks.type)) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tconst schema = validator?.body?.schema\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof schema === 'object' &&\n\t\t\t\t\t\t(hasType('File', schema) || hasType('Files', schema))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn `c.body = {}\n\n\t\t\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t\t\t}`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst aotParse = getAotParser()\n\n\t\t\tif (aotParse) fnLiteral += aotParse\n\t\t\telse {\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t\tfnLiteral += hasHeaders\n\t\t\t\t\t? `let contentType = c.headers['content-type']`\n\t\t\t\t\t: `let contentType = c.request.headers.get('content-type')`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tif (contentType) {\n\t\t\t\t\tconst index = contentType.indexOf(';')\n\t\t\t\t\tif (index !== -1) contentType = contentType.substring(0, index)\\n`\n\n\t\t\t\tif (hooks.parse.length) {\n\t\t\t\t\tfnLiteral += `let used = false\\n`\n\n\t\t\t\t\tconst endReport = report('parse', {\n\t\t\t\t\t\tunit: hooks.parse.length\n\t\t\t\t\t})\n\n\t\t\t\t\tfor (let i = 0; i < hooks.parse.length; i++) {\n\t\t\t\t\t\tconst endUnit = report('parse.unit', {\n\t\t\t\t\t\t\tname: hooks.parse[i].fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tconst name = `bo${i}`\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `if(!used) {\\n`\n\n\t\t\t\t\t\tfnLiteral += `let ${name} = parse[${i}](c, contentType)\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} instanceof Promise) ${name} = await ${name}\\n`\n\t\t\t\t\t\tfnLiteral += `if(${name} !== undefined) { c.body = ${name}; used = true }\\n`\n\n\t\t\t\t\t\tendUnit()\n\n\t\t\t\t\t\tif (i !== 0) fnLiteral += `}`\n\t\t\t\t\t}\n\n\t\t\t\t\tendReport()\n\t\t\t\t}\n\n\t\t\t\tif (hooks.parse.length) fnLiteral += `if (!used)`\n\n\t\t\t\tfnLiteral += `\n\t\t\t\tswitch (contentType) {\n\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t${\n\t\t\t\t\t\t\thasErrorHandler\n\t\t\t\t\t\t\t\t? `\n\t\t\t\t\t\tconst tempBody = await c.request.text()\n\t\t\t\t\t\t\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tc.body = JSON.parse(tempBody)\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow new ParseError('Failed to parse body as found: ' + (typeof body === \"string\" ? \"'\" + body + \"'\" : body), body)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t: `c.body = await c.request.json()\\n`\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\tc.body = await c.request.text()\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\tc.body = parseQuery(await c.request.text())\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\tc.body = await c.request.arrayBuffer();\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\tc.body = {}\n\n\t\t\t\t\t\tconst form = await c.request.formData()\n\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\tif (c.body[key])\n\t\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\tc.body[key] = value[0]\n\t\t\t\t\t\t\telse c.body[key] = value\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\\n`\n\n\t\t\t\tfnLiteral += '}\\n'\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += '\\n'\n\t}\n\n\tendParse()\n\n\tif (hooks?.transform) {\n\t\tconst endTransform = report('transform', {\n\t\t\tunit: hooks.transform.length\n\t\t})\n\n\t\tif (hooks.transform.length) fnLiteral += '\\nlet transformed\\n'\n\n\t\tfor (let i = 0; i < hooks.transform.length; i++) {\n\t\t\tconst transform = hooks.transform[i]\n\n\t\t\tconst endUnit = report('transform.unit', {\n\t\t\t\tname: transform.fn.name\n\t\t\t})\n\n\t\t\tfnLiteral += isAsync(transform)\n\t\t\t\t? `transformed = await transform[${i}](c)\\n`\n\t\t\t\t: `transformed = transform[${i}](c)\\n`\n\n\t\t\tfnLiteral += `if(transformed?.[ELYSIA_RESPONSE])\n\t\t\t\tthrow transformed\n\t\t\telse\n\t\t\t\tObject.assign(c, transformed)\\n`\n\n\t\t\tendUnit()\n\t\t}\n\n\t\tendTransform()\n\t}\n\n\tif (validator) {\n\t\tfnLiteral += '\\n'\n\n\t\tif (validator.headers) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.headers.params))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.headers.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.headers['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(headers.Check(c.headers) === false) {\n\t\t\t\t${composeValidation('headers')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.headers.schema))\n\t\t\t\tfnLiteral += `\\nc.headers = headers.Decode(c.headers)\\n`\n\t\t}\n\n\t\tif (validator.params) {\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.params.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.params.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed)\n\t\t\t\t\t\tfnLiteral += `c.params['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(params.Check(c.params) === false) {\n\t\t\t\t${composeValidation('params')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.params.schema))\n\t\t\t\tfnLiteral += `\\nc.params = params.Decode(c.params)\\n`\n\t\t}\n\n\t\tif (validator.query) {\n\t\t\tif (normalize) fnLiteral += 'c.query = query.Clean(c.query);\\n'\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.query.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tvalidator.query.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tconst parsed =\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: `'${value}'`\n\n\t\t\t\t\tif (parsed) fnLiteral += `c.query['${key}'] ??= ${parsed}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(query.Check(c.query) === false) {\n\t\t\t\t${composeValidation('query')}\n\t\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.query.schema))\n\t\t\t\t// Decode doesn't work with Object.create(null)\n\t\t\t\tfnLiteral += `\\nc.query = query.Decode(Object.assign({}, c.query))\\n`\n\t\t}\n\n\t\tif (validator.body) {\n\t\t\tif (normalize) fnLiteral += 'c.body = body.Clean(c.body);\\n'\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', validator.body.schema))\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n \t\t\t\tc.body = Object.assign(${JSON.stringify(\n\t\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tvalidator.body.schema,\n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t) ?? {}\n\t\t\t\t\t)}, c.body)\n\n \t\t\t\tif(body.Check(c.query) === false) {\n \t\t\t\t${composeValidation('body')}\n \t\t\t}\n }`\n\t\t\telse\n\t\t\t\tfnLiteral += `if(body.Check(c.body) === false) {\n\t\t\t${composeValidation('body')}\n\t\t}`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasTransform(validator.body.schema))\n\t\t\t\tfnLiteral += `\\nc.body = body.Decode(c.body)\\n`\n\t\t}\n\n\t\t// @ts-ignore\n\t\tif (isNotEmpty(cookieValidator?.schema.properties ?? {})) {\n\t\t\tfnLiteral += `const cookieValue = {}\n \t\t\tfor(const [key, value] of Object.entries(c.cookie))\n \t\t\t\tcookieValue[key] = value.value\\n`\n\n\t\t\t// @ts-ignore\n\t\t\tif (hasProperty('default', cookieValidator.schema))\n\t\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\t\tValue.Default(\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tcookieValidator.schema,\n\t\t\t\t\t\t{}\n\t\t\t\t\t) as Object\n\t\t\t\t)) {\n\t\t\t\t\tfnLiteral += `cookieValue['${key}'] = ${\n\t\t\t\t\t\ttypeof value === 'object'\n\t\t\t\t\t\t\t? JSON.stringify(value)\n\t\t\t\t\t\t\t: value\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\n\t\t\tfnLiteral += `if(cookie.Check(cookieValue) === false) {\n\t\t\t\t${composeValidation('cookie', 'cookieValue')}\n\t\t\t}`\n\n\t\t\t// // @ts-ignore\n\t\t\t// if (hasTransform(validator.cookie.schema))\n\t\t\t// \tfnLiteral += `\\nc.cookie = params.Decode(c.cookie)\\n`\n\t\t}\n\t}\n\n\tif (hooks?.beforeHandle) {\n\t\tconst endBeforeHandle = report('beforeHandle', {\n\t\t\tunit: hooks.beforeHandle.length\n\t\t})\n\n\t\tlet hasResolve = false\n\n\t\tfor (let i = 0; i < hooks.beforeHandle.length; i++) {\n\t\t\tconst beforeHandle = hooks.beforeHandle[i]\n\n\t\t\tconst endUnit = report('beforeHandle.unit', {\n\t\t\t\tname: beforeHandle.fn.name\n\t\t\t})\n\n\t\t\tconst returning = hasReturn(beforeHandle.fn.toString())\n\n\t\t\tconst isResolver = beforeHandle.subType === 'resolve'\n\n\t\t\tif (isResolver) {\n\t\t\t\tif (!hasResolve) {\n\t\t\t\t\thasResolve = true\n\t\t\t\t\tfnLiteral += '\\nlet resolved\\n'\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `resolved = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `resolved = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tfnLiteral += `if(resolved[ELYSIA_RESPONSE])\n\t\t\t\t\t\tthrow resolved\n\t\t\t\t\telse\n\t\t\t\t\t\tObject.assign(c, resolved)\\n`\n\t\t\t} else if (!returning) {\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += `Object.assign(c, be);`\n\t\t\t\tfnLiteral += isAsync(beforeHandle)\n\t\t\t\t\t? `be = await beforeHandle[${i}](c);\\n`\n\t\t\t\t\t: `be = beforeHandle[${i}](c);\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(be !== undefined) {\\n`\n\t\t\t\tendBeforeHandle()\n\t\t\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\t\t\tunit: hooks.transform.length\n\t\t\t\t})\n\t\t\t\tif (hooks.afterHandle) {\n\t\t\t\t\treport('handle', {\n\t\t\t\t\t\tname: isHandleFn\n\t\t\t\t\t\t\t? (handler as Function).name\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t})()\n\n\t\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\t\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\t\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\t\t\t\tname: hook.fn.name\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tfnLiteral += `c.response = be\\n`\n\n\t\t\t\t\t\tif (!returning) {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `await afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t\t\t: `afterHandle[${i}](c, be)\\n`\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\t\t\t\tfnLiteral += `if(af !== undefined) { c.response = be = af }\\n`\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tendUnit()\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tendAfterHandle()\n\n\t\t\t\tif (validator.response)\n\t\t\t\t\tfnLiteral += composeResponseValidation('be')\n\n\t\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\t\tfnLiteral += `c.response = be`\n\n\t\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\t\t\t\tif(mr !== undefined) c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfnLiteral += encodeCookie\n\t\t\t\tfnLiteral += `return mapEarlyResponse(be, c.set, c.request)}\\n`\n\t\t\t}\n\t\t}\n\n\t\tendBeforeHandle()\n\t}\n\n\tif (hooks?.afterHandle.length) {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (hooks.afterHandle.length)\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = c.response = await ${handle};\\n`\n\t\t\t\t: `let r = c.response = ${handle};\\n`\n\t\telse\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\tendHandle()\n\n\t\tconst endAfterHandle = report('afterHandle', {\n\t\t\tunit: hooks.afterHandle.length\n\t\t})\n\n\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\tconst hook = hooks.afterHandle[i]\n\n\t\t\tconst returning = hasReturn(hook.fn.toString())\n\n\t\t\tconst endUnit = report('afterHandle.unit', {\n\t\t\t\tname: hook.fn.name\n\t\t\t})\n\n\t\t\tif (!returning) {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\t\t\t} else {\n\t\t\t\tfnLiteral += isAsync(hook.fn)\n\t\t\t\t\t? `af = await afterHandle[${i}](c)\\n`\n\t\t\t\t\t: `af = afterHandle[${i}](c)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tif (validator.response) {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += composeResponseValidation('af')\n\n\t\t\t\t\tfnLiteral += `c.response = af }`\n\t\t\t\t} else {\n\t\t\t\t\tfnLiteral += `if(af !== undefined) {`\n\t\t\t\t\tendAfterHandle()\n\n\t\t\t\t\tfnLiteral += `c.response = af}\\n`\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tendAfterHandle()\n\n\t\tfnLiteral += `r = c.response\\n`\n\n\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\tfnLiteral += encodeCookie\n\n\t\tif (hooks.mapResponse.length) {\n\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\tfnLiteral += `\\nmr = onMapResponse[${i}](c)\n\t\t\t\tif(mr instanceof Promise) mr = await mr\n\t\t\t\tif(mr !== undefined) c.response = mr\\n`\n\t\t\t}\n\t\t}\n\n\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t} else {\n\t\tconst endHandle = report('handle', {\n\t\t\tname: isHandleFn ? (handler as Function).name : undefined\n\t\t})\n\n\t\tif (validator.response || hooks.mapResponse.length) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\tif (validator.response) fnLiteral += composeResponseValidation()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) { \n\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else if (traceConditions.handle || hasCookie) {\n\t\t\tfnLiteral += isAsyncHandler\n\t\t\t\t? `let r = await ${handle};\\n`\n\t\t\t\t: `let r = ${handle};\\n`\n\n\t\t\tendHandle()\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (hooks.mapResponse.length) {\n\t\t\t\tfnLiteral += 'c.response = r'\n\t\t\t\tfor (let i = 0; i < hooks.mapResponse.length; i++) {\n\t\t\t\t\tfnLiteral += `\\nif(mr === undefined) {\n\t\t\t\t\t\t\tmr = onMapResponse[${i}](c)\n\t\t\t\t\t\t\tif(mr instanceof Promise) mr = await mr\n \t\t\t\t\t\tif(mr !== undefined) r = c.response = mr\n\t\t\t\t\t\t}\\n`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfnLiteral += encodeCookie\n\n\t\t\tif (hasSet) fnLiteral += `return mapResponse(r, c.set, c.request)\\n`\n\t\t\telse fnLiteral += `return mapCompactResponse(r, c.request)\\n`\n\t\t} else {\n\t\t\tendHandle()\n\n\t\t\tconst handled = isAsyncHandler ? `await ${handle}` : handle\n\n\t\t\treport('afterHandle')()\n\n\t\t\tif (handler instanceof Response) {\n\t\t\t\tfnLiteral += inference.set\n\t\t\t\t\t? `if(\n\t\t\t\t\tisNotEmpty(c.set.headers) ||\n\t\t\t\t\tc.set.status !== 200 ||\n\t\t\t\t\tc.set.redirect ||\n\t\t\t\t\tc.set.cookie\n\t\t\t\t)\n\t\t\t\t\treturn mapResponse(${handle}.clone(), c.set, c.request)\n\t\t\t\telse\n\t\t\t\t\treturn ${handle}.clone()`\n\t\t\t\t\t: `return ${handle}.clone()`\n\n\t\t\t\tfnLiteral += '\\n'\n\t\t\t} else if (hasSet)\n\t\t\t\tfnLiteral += `return mapResponse(${handled}, c.set, c.request)\\n`\n\t\t\telse\n\t\t\t\tfnLiteral += `return mapCompactResponse(${handled}, c.request)\\n`\n\t\t}\n\t}\n\n\tif (hasErrorHandler || handleResponse) {\n\t\tfnLiteral += `\\n} catch(error) {`\n\t\tif (!maybeAsync) fnLiteral += `return (async () => {`\n\n\t\tfnLiteral += `const set = c.set\\nif (!set.status || set.status < 300) set.status = error?.status || 500\\n`\n\n\t\tconst endError = report('error', {\n\t\t\tunit: hooks.error.length\n\t\t})\n\n\t\tif (hooks.error.length) {\n\t\t\tfnLiteral += `\n\t\t\t\tc.error = error\n\t\t\t\tc.code = error.code ?? error[ERROR_CODE] ?? \"UNKNOWN\"\n\t\t\t`\n\n\t\t\tfor (let i = 0; i < hooks.error.length; i++) {\n\t\t\t\tconst name = `er${i}`\n\t\t\t\tconst endUnit = report('error.unit', {\n\t\t\t\t\tname: hooks.error[i].fn.name\n\t\t\t\t})\n\n\t\t\t\tfnLiteral += `\\nlet ${name} = handleErrors[${i}](c)\\n`\n\n\t\t\t\tif (isAsync(hooks.error[i]))\n\t\t\t\t\tfnLiteral += `if (${name} instanceof Promise) ${name} = await ${name}\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `${name} = mapEarlyResponse(${name}, set, c.request)\\n`\n\t\t\t\tfnLiteral += `if (${name}) {`\n\t\t\t\tfnLiteral += `return ${name} }\\n`\n\t\t\t}\n\t\t}\n\n\t\tendError()\n\n\t\tfnLiteral += `return handleError(c, error, true)\\n\\n`\n\n\t\tif (!maybeAsync) fnLiteral += '})()'\n\n\t\tfnLiteral += '}'\n\n\t\tif (handleResponse || hasTrace) {\n\t\t\tfnLiteral += ` finally { `\n\n\t\t\tconst endResponse = report('response', {\n\t\t\t\tunit: hooks.onResponse.length\n\t\t\t})\n\n\t\t\tfnLiteral += handleResponse\n\n\t\t\tendResponse()\n\n\t\t\tfnLiteral += `}`\n\t\t}\n\t}\n\n\tfnLiteral = `const {\n\t\thandler,\n\t\thandleError,\n\t\thooks: {\n\t\t\ttransform,\n\t\t\tresolve,\n\t\t\tbeforeHandle,\n\t\t\tafterHandle,\n\t\t\tmapResponse: onMapResponse,\n\t\t\tparse,\n\t\t\terror: handleErrors,\n\t\t\tonResponse\n\t\t},\n\t\tvalidator: {\n\t\t\tbody,\n\t\t\theaders,\n\t\t\tparams,\n\t\t\tquery,\n\t\t\tresponse,\n\t\t\tcookie\n\t\t},\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema,\n\t\tdefinitions,\n\t\tERROR_CODE,\n\t\tgetReporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t} = hooks\n\n\t${\n\t\thooks.onResponse.length\n\t\t\t? `const ${hooks.onResponse\n\t\t\t\t\t.map((x, i) => `res${i} = onResponse[${i}]`)\n\t\t\t\t\t.join(',')}`\n\t\t\t: ''\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function handle(c) {\n\t\t${hooks.beforeHandle.length ? 'let be' : ''}\n\t\t${hooks.afterHandle.length ? 'let af' : ''}\n\t\t${hooks.mapResponse.length ? 'let mr' : ''}\n\n\t\t${allowMeta ? 'c.schema = schema; c.defs = definitions' : ''}\n\t\t${fnLiteral}\n\t}`\n\n\tconst createHandler = Function('hooks', fnLiteral)\n\n\treturn createHandler({\n\t\thandler,\n\t\thooks: lifeCycleToFn(hooks),\n\t\tvalidator,\n\t\t// @ts-expect-error\n\t\thandleError: app.handleError,\n\t\tutils: {\n\t\t\tmapResponse,\n\t\t\tmapCompactResponse,\n\t\t\tmapEarlyResponse,\n\t\t\tparseQuery,\n\t\t\tisNotEmpty\n\t\t},\n\t\terror: {\n\t\t\tNotFoundError,\n\t\t\tValidationError,\n\t\t\tInternalServerError,\n\t\t\tParseError\n\t\t},\n\t\tschema: app.router.history,\n\t\t// @ts-expect-error\n\t\tdefinitions: app.definitions.type,\n\t\tERROR_CODE,\n\t\t// @ts-expect-error\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\tparseCookie,\n\t\tsignCookie,\n\t\tdecodeURIComponent,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const composeGeneralHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tconst inference = {\n\t\tevent: {\n\t\t\t// @ts-expect-error\n\t\t\t...app.inference.event,\n\t\t\t// @ts-expect-error\n\t\t\tqueries: [...app.inference.event.queries]\n\t\t},\n\t\t// @ts-expect-error\n\t\ttrace: { ...app.inference.trace }\n\t}\n\n\tlet decoratorsLiteral = ''\n\tlet fnLiteral = ''\n\n\t// @ts-expect-error private\n\tconst defaultHeaders = app.setHeaders\n\n\t// @ts-ignore\n\tfor (const key of Object.keys(app.singleton.decorator))\n\t\tdecoratorsLiteral += `,${key}: app.singleton.decorator.${key}`\n\n\tconst router = app.router\n\tconst hasTrace = app.event.trace.length > 0\n\n\tlet findDynamicRoute = `\n\tconst route = router.find(request.method, path) ${\n\t\trouter.http.root.ALL ? '?? router.find(\"ALL\", path)' : ''\n\t}\n\n\tif (route === null)\n\t\treturn ${\n\t\t\tapp.event.error.length\n\t\t\t\t? `app.handleError(ctx, notFound)`\n\t\t\t\t: app.event.request.length\n\t\t\t\t? `new Response(error404Message, {\n\t\t\t\t\tstatus: ctx.set.status === 200 ? 404 : ctx.set.status,\n\t\t\t\t\theaders: ctx.set.headers\n\t\t\t\t})`\n\t\t\t\t: `error404.clone()`\n\t\t}\n\n\tctx.params = route.params\\n`\n\n\tconst shouldPrecompile =\n\t\tapp.config.precompile === true ||\n\t\t(typeof app.config.precompile === 'object' &&\n\t\t\tapp.config.precompile.compose === true)\n\n\tif (!shouldPrecompile)\n\t\tfindDynamicRoute += `\n\t\t\tif(route.store.composed)\n\t\t\t\treturn route.store.composed(ctx)\n\n\t\t\tif(route.store.compose)\n\t\t\t\treturn (route.store.compose())(ctx)`\n\telse findDynamicRoute += `return route.store(ctx)`\n\n\tfindDynamicRoute += '\\n'\n\n\tlet switchMap = ``\n\tfor (const [path, { code, all }] of Object.entries(router.static.http.map))\n\t\tswitchMap += `case '${path}':\\nswitch(request.method) {\\n${code}\\n${\n\t\t\tall ?? `default: break map`\n\t\t}}\\n\\n`\n\n\tconst maybeAsync = app.event.request.some(isAsync)\n\n\tconst init = `\\n\n\tconst url = request.url\n\tconst s = url.indexOf('/', 11)\n\tconst qi = url.indexOf('?', s + 1)\n\tlet path\n\tif(qi === -1)\n\t\tpath = url.substring(s)\n\telse \n\t\tpath = url.substring(s, qi)\\n`\n\n\tfnLiteral += `const {\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\trequestId,\n\t\tgetReporter,\n\t\thandleError,\n\t\terror\n\t} = data\n\n\tconst store = app.singleton.store\n\tconst staticRouter = app.router.static.http\n\tconst wsRouter = app.router.ws\n\tconst router = app.router.http\n\n\tconst notFound = new NotFoundError()\n\n\t${\n\t\tapp.event.request.length\n\t\t\t? `const onRequest = app.event.request.map(x => x.fn)`\n\t\t\t: ''\n\t}\n\t${router.static.http.variables}\n\t${\n\t\tapp.event.error.length\n\t\t\t? ''\n\t\t\t: `\n\tconst error404Message = notFound.message.toString()\n\tconst error404 = new Response(error404Message, { status: 404 });\n\t`\n\t}\n\n\treturn ${maybeAsync ? 'async' : ''} function map(request) {\\n`\n\n\tif (app.event.request.length) fnLiteral += `let re`\n\n\tconst report = createReport({\n\t\thasTrace,\n\t\thasTraceSet: inference.trace.set,\n\t\tcondition: {\n\t\t\trequest: inference.trace.request\n\t\t},\n\t\taddFn: (word) => {\n\t\t\tfnLiteral += word\n\t\t}\n\t})\n\n\tif (app.event.request.length) {\n\t\tfnLiteral += `\n\t\t\t${hasTrace ? 'const id = +requestId.value++' : ''}\n\n\t\t\tconst ctx = {\n\t\t\t\trequest,\n\t\t\t\tstore,\n\t\t\t\tset: {\n\t\t\t\t\theaders: ${\n\t\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t\t: '{}'\n\t\t\t\t\t},\n\t\t\t\t\tstatus: 200\n\t\t\t\t},\n\t\t\t\terror\n\t\t\t\t${hasTrace ? ',$$requestId: +id' : ''}\n\t\t\t\t${decoratorsLiteral}\n\t\t\t}\n\t\t`\n\n\t\tconst endReport = report('request', {\n\t\t\tattribute: 'ctx',\n\t\t\tunit: app.event.request.length\n\t\t})\n\n\t\tfnLiteral += `\\n try {\\n`\n\n\t\tfor (let i = 0; i < app.event.request.length; i++) {\n\t\t\tconst hook = app.event.request[i]\n\t\t\tconst withReturn = hasReturn(hook.fn.toString())\n\t\t\tconst maybeAsync = isAsync(hook)\n\n\t\t\tconst endUnit = report('request.unit', {\n\t\t\t\tname: app.event.request[i].fn.name\n\t\t\t})\n\n\t\t\tif (withReturn) {\n\t\t\t\tfnLiteral += `re = mapEarlyResponse(\n\t\t\t\t\t${maybeAsync ? 'await' : ''} onRequest[${i}](ctx),\n\t\t\t\t\tctx.set,\n\t\t\t\t\trequest\n\t\t\t\t)\\n`\n\n\t\t\t\tendUnit()\n\n\t\t\t\tfnLiteral += `if(re !== undefined) return re\\n`\n\t\t\t} else {\n\t\t\t\tfnLiteral += `${\n\t\t\t\t\tmaybeAsync ? 'await' : ''\n\t\t\t\t} onRequest[${i}](ctx)\\n`\n\t\t\t\tendUnit()\n\t\t\t}\n\t\t}\n\n\t\tfnLiteral += `} catch (error) {\n\t\t\treturn app.handleError(ctx, error)\n\t\t}`\n\n\t\tendReport()\n\n\t\tfnLiteral += init\n\t\tfnLiteral += `\\nctx.qi = qi\\n ctx.path = path\\n`\n\t} else {\n\t\tfnLiteral += init\n\t\tfnLiteral += `${hasTrace ? 'const id = +requestId.value++' : ''}\n\t\tconst ctx = {\n\t\t\trequest,\n\t\t\tstore,\n\t\t\tqi,\n\t\t\tpath,\n\t\t\tset: {\n\t\t\t\theaders: ${\n\t\t\t\t\tObject.keys(defaultHeaders ?? {}).length\n\t\t\t\t\t\t? 'Object.assign({}, app.setHeaders)'\n\t\t\t\t\t\t: '{}'\n\t\t\t\t},\n\t\t\t\tstatus: 200\n\t\t\t},\n\t\t\terror\n\t\t\t${hasTrace ? ',$$requestId: id' : ''}\n\t\t\t${decoratorsLiteral}\n\t\t}`\n\n\t\treport('request', {\n\t\t\tunit: app.event.request.length,\n\t\t\tattribute:\n\t\t\t\tinference.trace.context ||\n\t\t\t\tinference.trace.store ||\n\t\t\t\tinference.trace.set\n\t\t\t\t\t? 'ctx'\n\t\t\t\t\t: ''\n\t\t})()\n\t}\n\n\tconst wsPaths = app.router.static.ws\n\tconst wsRouter = app.router.ws\n\n\tif (Object.keys(wsPaths).length || wsRouter.history.length) {\n\t\tfnLiteral += `\n\t\t\tif(request.method === 'GET') {\n\t\t\t\tswitch(path) {`\n\n\t\tfor (const [path, index] of Object.entries(wsPaths)) {\n\t\t\tfnLiteral += `\n\t\t\t\t\tcase '${path}':\n\t\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket')\n\t\t\t\t\t\t\treturn st${index}(ctx)\n\n\t\t\t\t\t\tbreak`\n\t\t}\n\n\t\tfnLiteral += `\n\t\t\t\tdefault:\n\t\t\t\t\tif(request.headers.get('upgrade') === 'websocket') {\n\t\t\t\t\t\tconst route = wsRouter.find('ws', path)\n\n\t\t\t\t\t\tif(route) {\n\t\t\t\t\t\t\tctx.params = route.params\n\n\t\t\t\t\t\t\treturn route.store(ctx)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\\n`\n\t}\n\n\tfnLiteral += `\n\t\tmap: switch(path) {\n\t\t\t${switchMap}\n\n\t\t\tdefault:\n\t\t\t\tbreak\n\t\t}\n\n\t\t${findDynamicRoute}\n\t}`\n\n\tconst handleError = composeErrorHandler(app) as any\n\n\t// @ts-ignore\n\tapp.handleError = handleError\n\n\treturn Function(\n\t\t'data',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapEarlyResponse,\n\t\tNotFoundError,\n\t\t// @ts-ignore\n\t\tgetReporter: () => app.reporter,\n\t\trequestId,\n\t\thandleError,\n\t\terror\n\t})\n}\n\nexport const composeErrorHandler = (\n\tapp: Elysia<any, any, any, any, any, any, any, any>\n) => {\n\tlet fnLiteral = `const {\n\t\tapp: { event: { error: onErrorContainer, onResponse: resContainer } },\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t} = inject\n\n\tconst onError = onErrorContainer.map(x => x.fn)\n\tconst res = resContainer.map(x => x.fn)\n\n\treturn ${\n\t\tapp.event.error.find(isAsync) ? 'async' : ''\n\t} function(context, error, skipGlobal) {\n\t\tlet r\n\n\t\tconst { set } = context\n\n\t\tcontext.code = error.code\n\t\tcontext.error = error\n\n\t\tif(ELYSIA_RESPONSE in error) {\n\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\terror.message = error.response\n\t\t}\\n`\n\n\tfor (let i = 0; i < app.event.error.length; i++) {\n\t\tconst handler = app.event.error[i]\n\n\t\tconst response = `${\n\t\t\tisAsync(handler) ? 'await ' : ''\n\t\t}onError[${i}](context)`\n\n\t\tfnLiteral += '\\nif(skipGlobal !== true) {\\n'\n\n\t\tif (hasReturn(handler.fn.toString()))\n\t\t\tfnLiteral += `r = ${response}; if(r !== undefined) {\n\t\t\t\tif(r instanceof Response) return r\n\n\t\t\t\tif(r[ELYSIA_RESPONSE]) {\n\t\t\t\t\terror.status = error[ELYSIA_RESPONSE]\n\t\t\t\t\terror.message = error.response\n\t\t\t\t}\n\t\t\n\t\t\t\tif(set.status === 200) set.status = error.status\n\t\t\t\treturn mapResponse(r, set, context.request)\n\t\t\t}\\n`\n\t\telse fnLiteral += response + '\\n'\n\n\t\tfnLiteral += '\\n}\\n'\n\t}\n\n\tfnLiteral += `if(error.constructor.name === \"ValidationError\" || error.constructor.name === \"TransformDecodeError\") {\n\t\tset.status = error.status ?? 422\n\t\treturn new Response(\n\t\t\terror.message,\n\t\t\t{ \n\t\t\t\theaders: Object.assign(\n\t\t\t\t\t{ 'content-type': 'application/json'}, \n\t\t\t\t\tset.headers\n\t\t\t\t), \n\t\t\t\tstatus: set.status\n\t\t\t}\n\t\t)\n\t} else {\n\t\tif(error.code && typeof error.status === \"number\")\n\t\t\treturn new Response(\n\t\t\t\terror.message,\n\t\t\t\t{ headers: set.headers, status: error.status }\n\t\t\t)\n\n\t\treturn mapResponse(error, set, context.request)\n\t}\n}`\n\n\treturn Function(\n\t\t'inject',\n\t\tfnLiteral\n\t)({\n\t\tapp,\n\t\tmapResponse,\n\t\tERROR_CODE,\n\t\tELYSIA_RESPONSE\n\t})\n}\n\nexport const jitRoute = (\n\tindex: number\n) => `if(stc${index}) return stc${index}(ctx)\nif(st${index}.compose) return (stc${index} = st${index}.compose())(ctx)\n\nreturn st${index}(ctx)`\n",
27
27
  "import type { Elysia } from '.'\n\nimport { mapEarlyResponse, mapResponse } from './handler'\nimport { ElysiaErrors, NotFoundError, ValidationError } from './error'\n\nimport type { Context } from './context'\n\nimport { parse as parseQuery } from 'fast-querystring'\n\nimport { signCookie } from './utils'\nimport { parseCookie } from './cookies'\n\nimport type { Handler, LifeCycleStore, SchemaValidator } from './types'\n\n// JIT Handler\nexport type DynamicHandler = {\n\thandle: Handler<any, any>\n\tcontent?: string\n\thooks: LifeCycleStore\n\tvalidator?: SchemaValidator\n}\n\nexport const createDynamicHandler =\n\t(app: Elysia<any, any, any, any, any, any, any, any>) =>\n\tasync (request: Request): Promise<Response> => {\n\t\tconst url = request.url,\n\t\t\ts = url.indexOf('/', 11),\n\t\t\tqi = url.indexOf('?', s + 1),\n\t\t\tpath = qi === -1 ? url.substring(s) : url.substring(s, qi)\n\n\t\tconst set: Context['set'] = {\n\t\t\tcookie: {},\n\t\t\tstatus: 200,\n\t\t\theaders: {}\n\t\t}\n\n\t\tconst context = Object.assign(\n\t\t\t{},\n\t\t\t// @ts-expect-error\n\t\t\tapp.singleton.decorator,\n\t\t\t{\n\t\t\t\tset,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tstore: app.singleton.store,\n\t\t\t\trequest,\n\t\t\t\tpath,\n\t\t\t\tqi\n\t\t\t}\n\t\t) as unknown as Context\n\n\t\ttry {\n\t\t\tfor (let i = 0; i < app.event.request.length; i++) {\n\t\t\t\tconst onRequest = app.event.request[i].fn\n\t\t\t\tlet response = onRequest(context as any)\n\t\t\t\tif (response instanceof Promise) response = await response\n\n\t\t\t\tresponse = mapEarlyResponse(response, set)\n\t\t\t\tif (response) return response\n\t\t\t}\n\n\t\t\tconst handler =\n\t\t\t\tapp.router.dynamic.find(request.method, path) ??\n\t\t\t\tapp.router.dynamic.find('ALL', path)\n\n\t\t\tif (!handler) throw new NotFoundError()\n\n\t\t\tconst { handle, hooks, validator, content } = handler.store\n\n\t\t\tlet body: string | Record<string, any> | undefined\n\t\t\tif (request.method !== 'GET' && request.method !== 'HEAD') {\n\t\t\t\tif (content) {\n\t\t\t\t\tswitch (content) {\n\t\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t\tbody = (await request.json()) as any\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\t\tbody = await request.text()\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\t\tbody = parseQuery(await request.text())\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\t\tbody = await request.arrayBuffer()\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\t\tbody = {}\n\n\t\t\t\t\t\t\tconst form = await request.formData()\n\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\tif (body[key]) continue\n\n\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\tif (value.length === 1) body[key] = value[0]\n\t\t\t\t\t\t\t\telse body[key] = value\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet contentType = request.headers.get('content-type')\n\n\t\t\t\t\tif (contentType) {\n\t\t\t\t\t\tconst index = contentType.indexOf(';')\n\t\t\t\t\t\tif (index !== -1)\n\t\t\t\t\t\t\tcontentType = contentType.slice(0, index)\n\n\t\t\t\t\t\tfor (let i = 0; i < hooks.parse.length; i++) {\n\t\t\t\t\t\t\tconst hook = hooks.parse[i].fn\n\t\t\t\t\t\t\tlet temp = hook(context, contentType)\n\t\t\t\t\t\t\tif (temp instanceof Promise) temp = await temp\n\n\t\t\t\t\t\t\tif (temp) {\n\t\t\t\t\t\t\t\tbody = temp\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// body might be empty string thus can't use !body\n\t\t\t\t\t\tif (body === undefined) {\n\t\t\t\t\t\t\tswitch (contentType) {\n\t\t\t\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t\t\t\tbody = (await request.json()) as any\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\t\t\t\tbody = await request.text()\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\t\t\t\tbody = parseQuery(await request.text())\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\t\t\t\tbody = await request.arrayBuffer()\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\t\t\t\tbody = {}\n\n\t\t\t\t\t\t\t\t\tconst form = await request.formData()\n\t\t\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\t\t\tif (body[key]) continue\n\n\t\t\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\t\t\t\tbody[key] = value[0]\n\t\t\t\t\t\t\t\t\t\telse body[key] = value\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcontext.body = body\n\t\t\t// @ts-expect-error\n\t\t\tcontext.params = handler?.params || undefined\n\t\t\tcontext.query = qi === -1 ? {} : parseQuery(url.substring(qi + 1))\n\n\t\t\tcontext.headers = {}\n\t\t\tfor (const [key, value] of request.headers.entries())\n\t\t\t\tcontext.headers[key] = value\n\n\t\t\tconst cookieMeta = Object.assign(\n\t\t\t\t{},\n\t\t\t\tapp.config?.cookie,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tvalidator?.cookie?.config\n\t\t\t) as {\n\t\t\t\tsecrets?: string | string[]\n\t\t\t\tsign: string[] | true\n\t\t\t\tproperties: { [x: string]: Object }\n\t\t\t}\n\n\t\t\tconst cookieHeaderValue = request.headers.get('cookie')\n\n\t\t\tcontext.cookie = await parseCookie(\n\t\t\t\tcontext.set,\n\t\t\t\tcookieHeaderValue,\n\t\t\t\tcookieMeta\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsecrets:\n\t\t\t\t\t\t\t\tcookieMeta.secrets !== undefined\n\t\t\t\t\t\t\t\t\t? typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t\t\t\t\t\t? cookieMeta.secrets\n\t\t\t\t\t\t\t\t\t\t: cookieMeta.secrets.join(',')\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tsign:\n\t\t\t\t\t\t\t\tcookieMeta.sign === true\n\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t: cookieMeta.sign !== undefined\n\t\t\t\t\t\t\t\t\t? typeof cookieMeta.sign === 'string'\n\t\t\t\t\t\t\t\t\t\t? cookieMeta.sign\n\t\t\t\t\t\t\t\t\t\t: cookieMeta.sign.join(',')\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t }\n\t\t\t\t\t: undefined\n\t\t\t)\n\n\t\t\tfor (let i = 0; i < hooks.transform.length; i++) {\n\t\t\t\tconst hook = hooks.transform[i]\n\t\t\t\tconst operation = hook.fn(context)\n\n\t\t\t\tif (hook.subType === 'derive') {\n\t\t\t\t\tif (operation instanceof Promise)\n\t\t\t\t\t\tObject.assign(context, await operation)\n\t\t\t\t\telse Object.assign(context, operation)\n\t\t\t\t} else if (operation instanceof Promise) await operation\n\t\t\t}\n\n\t\t\tif (validator) {\n\t\t\t\tif (validator.headers) {\n\t\t\t\t\tconst _header: Record<string, string> = {}\n\t\t\t\t\tfor (const key in request.headers)\n\t\t\t\t\t\t_header[key] = request.headers.get(key)!\n\n\t\t\t\t\tif (validator.headers.Check(_header) === false)\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t'header',\n\t\t\t\t\t\t\tvalidator.headers,\n\t\t\t\t\t\t\t_header\n\t\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tif (validator.params?.Check(context.params) === false)\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t'params',\n\t\t\t\t\t\tvalidator.params,\n\t\t\t\t\t\tcontext.params\n\t\t\t\t\t)\n\n\t\t\t\tif (validator.query?.Check(context.query) === false)\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t'query',\n\t\t\t\t\t\tvalidator.query,\n\t\t\t\t\t\tcontext.query\n\t\t\t\t\t)\n\n\t\t\t\tif (validator.cookie) {\n\t\t\t\t\tconst cookieValue: Record<string, unknown> = {}\n\t\t\t\t\tfor (const [key, value] of Object.entries(context.cookie))\n\t\t\t\t\t\tcookieValue[key] = value.value\n\n\t\t\t\t\tif (validator.cookie?.Check(cookieValue) === false)\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t'cookie',\n\t\t\t\t\t\t\tvalidator.cookie,\n\t\t\t\t\t\t\tcookieValue\n\t\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tif (validator.body?.Check(body) === false)\n\t\t\t\t\tthrow new ValidationError('body', validator.body, body)\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < hooks.beforeHandle.length; i++) {\n\t\t\t\tlet response = hooks.beforeHandle[i].fn(context)\n\t\t\t\tif (response instanceof Promise) response = await response\n\n\t\t\t\t// `false` is a falsey value, check for undefined instead\n\t\t\t\tif (response !== undefined) {\n\t\t\t\t\t;(\n\t\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t\t}\n\t\t\t\t\t).response = response\n\n\t\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\t\tlet newResponse = hooks.afterHandle[i].fn(\n\t\t\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (newResponse instanceof Promise)\n\t\t\t\t\t\t\tnewResponse = await newResponse\n\n\t\t\t\t\t\tif (newResponse) response = newResponse\n\t\t\t\t\t}\n\n\t\t\t\t\tconst result = mapEarlyResponse(response, context.set)\n\t\t\t\t\tif (result) return result\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet response = handle(context)\n\t\t\tif (response instanceof Promise) response = await response\n\n\t\t\tif (!hooks.afterHandle.length) {\n\t\t\t\tconst responseValidator = validator?.response?.[response.status]\n\n\t\t\t\tif (responseValidator?.Check(response) === false)\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t'response',\n\t\t\t\t\t\tresponseValidator,\n\t\t\t\t\t\tresponse\n\t\t\t\t\t)\n\t\t\t} else {\n\t\t\t\t;(\n\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t}\n\t\t\t\t).response = response\n\n\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\tlet newResponse = hooks.afterHandle[i].fn(\n\t\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t\tif (newResponse instanceof Promise)\n\t\t\t\t\t\tnewResponse = await newResponse\n\n\t\t\t\t\tconst result = mapEarlyResponse(newResponse, context.set)\n\t\t\t\t\tif (result !== undefined) {\n\t\t\t\t\t\tconst responseValidator =\n\t\t\t\t\t\t\tvalidator?.response?.[response.status]\n\n\t\t\t\t\t\tif (responseValidator?.Check(result) === false)\n\t\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t\t'response',\n\t\t\t\t\t\t\t\tresponseValidator,\n\t\t\t\t\t\t\t\tresult\n\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn result\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (context.set.cookie && cookieMeta?.sign) {\n\t\t\t\tconst secret = !cookieMeta.secrets\n\t\t\t\t\t? undefined\n\t\t\t\t\t: typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t? cookieMeta.secrets\n\t\t\t\t\t: cookieMeta.secrets[0]\n\n\t\t\t\tif (cookieMeta.sign === true)\n\t\t\t\t\tfor (const [key, cookie] of Object.entries(\n\t\t\t\t\t\tcontext.set.cookie\n\t\t\t\t\t))\n\t\t\t\t\t\tcontext.set.cookie[key].value = await signCookie(\n\t\t\t\t\t\t\tcookie.value as any,\n\t\t\t\t\t\t\t'${secret}'\n\t\t\t\t\t\t)\n\t\t\t\telse {\n\t\t\t\t\t// @ts-expect-error private\n\t\t\t\t\tconst properties = validator?.cookie?.schema?.properties\n\n\t\t\t\t\tfor (const name of cookieMeta.sign) {\n\t\t\t\t\t\tif (!(name in properties))\n\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\tif (context.set.cookie[name]?.value) {\n\t\t\t\t\t\t\tcontext.set.cookie[name].value = await signCookie(\n\t\t\t\t\t\t\t\tcontext.set.cookie[name].value as any,\n\t\t\t\t\t\t\t\tsecret as any\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mapResponse(response, context.set)\n\t\t} catch (error) {\n\t\t\tif ((error as ElysiaErrors).status)\n\t\t\t\tset.status = (error as ElysiaErrors).status\n\n\t\t\t// @ts-expect-error private\n\t\t\treturn app.handleError(context, error)\n\t\t} finally {\n\t\t\tfor (const onResponse of app.event.onResponse)\n\t\t\t\tawait onResponse.fn(context)\n\t\t}\n\t}\n\nexport const createDynamicErrorHandler =\n\t(app: Elysia<any, any, any, any, any, any, any, any>) =>\n\tasync (context: Context, error: ElysiaErrors) => {\n\t\tconst errorContext = Object.assign(context, { error, code: error.code })\n\t\terrorContext.set = context.set\n\n\t\tfor (let i = 0; i < app.event.error.length; i++) {\n\t\t\tconst hook = app.event.error[i]\n\t\t\tlet response = hook.fn(errorContext as any)\n\t\t\tif (response instanceof Promise) response = await response\n\t\t\tif (response !== undefined && response !== null)\n\t\t\t\treturn mapResponse(response, context.set)\n\t\t}\n\n\t\treturn new Response(\n\t\t\ttypeof error.cause === 'string' ? error.cause : error.message,\n\t\t\t{\n\t\t\t\theaders: context.set.headers,\n\t\t\t\tstatus: error.status ?? 500\n\t\t\t}\n\t\t)\n\t}\n",
28
28
  "import type { Elysia } from '.'\n\nimport { mapEarlyResponse, mapResponse } from './handler'\nimport { ElysiaErrors, NotFoundError, ValidationError } from './error'\n\nimport type { Context } from './context'\n\nimport { parse as parseQuery } from 'fast-querystring'\n\nimport { signCookie } from './utils'\nimport { parseCookie } from './cookies'\n\nimport type { Handler, LifeCycleStore, SchemaValidator } from './types'\n\n// JIT Handler\nexport type DynamicHandler = {\n\thandle: Handler<any, any>\n\tcontent?: string\n\thooks: LifeCycleStore\n\tvalidator?: SchemaValidator\n}\n\nexport const createDynamicHandler =\n\t(app: Elysia<any, any, any, any, any, any, any, any>) =>\n\tasync (request: Request): Promise<Response> => {\n\t\tconst url = request.url,\n\t\t\ts = url.indexOf('/', 11),\n\t\t\tqi = url.indexOf('?', s + 1),\n\t\t\tpath = qi === -1 ? url.substring(s) : url.substring(s, qi)\n\n\t\tconst set: Context['set'] = {\n\t\t\tcookie: {},\n\t\t\tstatus: 200,\n\t\t\theaders: {}\n\t\t}\n\n\t\tconst context = Object.assign(\n\t\t\t{},\n\t\t\t// @ts-expect-error\n\t\t\tapp.singleton.decorator,\n\t\t\t{\n\t\t\t\tset,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tstore: app.singleton.store,\n\t\t\t\trequest,\n\t\t\t\tpath,\n\t\t\t\tqi\n\t\t\t}\n\t\t) as unknown as Context\n\n\t\ttry {\n\t\t\tfor (let i = 0; i < app.event.request.length; i++) {\n\t\t\t\tconst onRequest = app.event.request[i].fn\n\t\t\t\tlet response = onRequest(context as any)\n\t\t\t\tif (response instanceof Promise) response = await response\n\n\t\t\t\tresponse = mapEarlyResponse(response, set)\n\t\t\t\tif (response) return response\n\t\t\t}\n\n\t\t\tconst handler =\n\t\t\t\tapp.router.dynamic.find(request.method, path) ??\n\t\t\t\tapp.router.dynamic.find('ALL', path)\n\n\t\t\tif (!handler) throw new NotFoundError()\n\n\t\t\tconst { handle, hooks, validator, content } = handler.store\n\n\t\t\tlet body: string | Record<string, any> | undefined\n\t\t\tif (request.method !== 'GET' && request.method !== 'HEAD') {\n\t\t\t\tif (content) {\n\t\t\t\t\tswitch (content) {\n\t\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t\tbody = (await request.json()) as any\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\t\tbody = await request.text()\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\t\tbody = parseQuery(await request.text())\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\t\tbody = await request.arrayBuffer()\n\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\t\tbody = {}\n\n\t\t\t\t\t\t\tconst form = await request.formData()\n\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\tif (body[key]) continue\n\n\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\tif (value.length === 1) body[key] = value[0]\n\t\t\t\t\t\t\t\telse body[key] = value\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet contentType = request.headers.get('content-type')\n\n\t\t\t\t\tif (contentType) {\n\t\t\t\t\t\tconst index = contentType.indexOf(';')\n\t\t\t\t\t\tif (index !== -1)\n\t\t\t\t\t\t\tcontentType = contentType.slice(0, index)\n\n\t\t\t\t\t\tfor (let i = 0; i < hooks.parse.length; i++) {\n\t\t\t\t\t\t\tconst hook = hooks.parse[i].fn\n\t\t\t\t\t\t\tlet temp = hook(context, contentType)\n\t\t\t\t\t\t\tif (temp instanceof Promise) temp = await temp\n\n\t\t\t\t\t\t\tif (temp) {\n\t\t\t\t\t\t\t\tbody = temp\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// body might be empty string thus can't use !body\n\t\t\t\t\t\tif (body === undefined) {\n\t\t\t\t\t\t\tswitch (contentType) {\n\t\t\t\t\t\t\t\tcase 'application/json':\n\t\t\t\t\t\t\t\t\tbody = (await request.json()) as any\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'text/plain':\n\t\t\t\t\t\t\t\t\tbody = await request.text()\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'application/x-www-form-urlencoded':\n\t\t\t\t\t\t\t\t\tbody = parseQuery(await request.text())\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'application/octet-stream':\n\t\t\t\t\t\t\t\t\tbody = await request.arrayBuffer()\n\t\t\t\t\t\t\t\t\tbreak\n\n\t\t\t\t\t\t\t\tcase 'multipart/form-data':\n\t\t\t\t\t\t\t\t\tbody = {}\n\n\t\t\t\t\t\t\t\t\tconst form = await request.formData()\n\t\t\t\t\t\t\t\t\tfor (const key of form.keys()) {\n\t\t\t\t\t\t\t\t\t\tif (body[key]) continue\n\n\t\t\t\t\t\t\t\t\t\tconst value = form.getAll(key)\n\t\t\t\t\t\t\t\t\t\tif (value.length === 1)\n\t\t\t\t\t\t\t\t\t\t\tbody[key] = value[0]\n\t\t\t\t\t\t\t\t\t\telse body[key] = value\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcontext.body = body\n\t\t\t// @ts-expect-error\n\t\t\tcontext.params = handler?.params || undefined\n\t\t\tcontext.query = qi === -1 ? {} : parseQuery(url.substring(qi + 1))\n\n\t\t\tcontext.headers = {}\n\t\t\tfor (const [key, value] of request.headers.entries())\n\t\t\t\tcontext.headers[key] = value\n\n\t\t\tconst cookieMeta = Object.assign(\n\t\t\t\t{},\n\t\t\t\tapp.config?.cookie,\n\t\t\t\t// @ts-expect-error\n\t\t\t\tvalidator?.cookie?.config\n\t\t\t) as {\n\t\t\t\tsecrets?: string | string[]\n\t\t\t\tsign: string[] | true\n\t\t\t\tproperties: { [x: string]: Object }\n\t\t\t}\n\n\t\t\tconst cookieHeaderValue = request.headers.get('cookie')\n\n\t\t\tcontext.cookie = await parseCookie(\n\t\t\t\tcontext.set,\n\t\t\t\tcookieHeaderValue,\n\t\t\t\tcookieMeta\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsecrets:\n\t\t\t\t\t\t\t\tcookieMeta.secrets !== undefined\n\t\t\t\t\t\t\t\t\t? typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t\t\t\t\t\t? cookieMeta.secrets\n\t\t\t\t\t\t\t\t\t\t: cookieMeta.secrets.join(',')\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tsign:\n\t\t\t\t\t\t\t\tcookieMeta.sign === true\n\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t: cookieMeta.sign !== undefined\n\t\t\t\t\t\t\t\t\t? typeof cookieMeta.sign === 'string'\n\t\t\t\t\t\t\t\t\t\t? cookieMeta.sign\n\t\t\t\t\t\t\t\t\t\t: cookieMeta.sign.join(',')\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t }\n\t\t\t\t\t: undefined\n\t\t\t)\n\n\t\t\tfor (let i = 0; i < hooks.transform.length; i++) {\n\t\t\t\tconst hook = hooks.transform[i]\n\t\t\t\tconst operation = hook.fn(context)\n\n\t\t\t\tif (hook.subType === 'derive') {\n\t\t\t\t\tif (operation instanceof Promise)\n\t\t\t\t\t\tObject.assign(context, await operation)\n\t\t\t\t\telse Object.assign(context, operation)\n\t\t\t\t} else if (operation instanceof Promise) await operation\n\t\t\t}\n\n\t\t\tif (validator) {\n\t\t\t\tif (validator.headers) {\n\t\t\t\t\tconst _header: Record<string, string> = {}\n\t\t\t\t\tfor (const key in request.headers)\n\t\t\t\t\t\t_header[key] = request.headers.get(key)!\n\n\t\t\t\t\tif (validator.headers.Check(_header) === false)\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t'header',\n\t\t\t\t\t\t\tvalidator.headers,\n\t\t\t\t\t\t\t_header\n\t\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tif (validator.params?.Check(context.params) === false)\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t'params',\n\t\t\t\t\t\tvalidator.params,\n\t\t\t\t\t\tcontext.params\n\t\t\t\t\t)\n\n\t\t\t\tif (validator.query?.Check(context.query) === false)\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t'query',\n\t\t\t\t\t\tvalidator.query,\n\t\t\t\t\t\tcontext.query\n\t\t\t\t\t)\n\n\t\t\t\tif (validator.cookie) {\n\t\t\t\t\tconst cookieValue: Record<string, unknown> = {}\n\t\t\t\t\tfor (const [key, value] of Object.entries(context.cookie))\n\t\t\t\t\t\tcookieValue[key] = value.value\n\n\t\t\t\t\tif (validator.cookie?.Check(cookieValue) === false)\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t'cookie',\n\t\t\t\t\t\t\tvalidator.cookie,\n\t\t\t\t\t\t\tcookieValue\n\t\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tif (validator.body?.Check(body) === false)\n\t\t\t\t\tthrow new ValidationError('body', validator.body, body)\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < hooks.beforeHandle.length; i++) {\n\t\t\t\tlet response = hooks.beforeHandle[i].fn(context)\n\t\t\t\tif (response instanceof Promise) response = await response\n\n\t\t\t\t// `false` is a falsey value, check for undefined instead\n\t\t\t\tif (response !== undefined) {\n\t\t\t\t\t;(\n\t\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t\t}\n\t\t\t\t\t).response = response\n\n\t\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\t\tlet newResponse = hooks.afterHandle[i].fn(\n\t\t\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (newResponse instanceof Promise)\n\t\t\t\t\t\t\tnewResponse = await newResponse\n\n\t\t\t\t\t\tif (newResponse) response = newResponse\n\t\t\t\t\t}\n\n\t\t\t\t\tconst result = mapEarlyResponse(response, context.set)\n\t\t\t\t\tif (result) return result\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet response = handle(context)\n\t\t\tif (response instanceof Promise) response = await response\n\n\t\t\tif (!hooks.afterHandle.length) {\n\t\t\t\tconst responseValidator = validator?.response?.[response.status]\n\n\t\t\t\tif (responseValidator?.Check(response) === false)\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t'response',\n\t\t\t\t\t\tresponseValidator,\n\t\t\t\t\t\tresponse\n\t\t\t\t\t)\n\t\t\t} else {\n\t\t\t\t;(\n\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t}\n\t\t\t\t).response = response\n\n\t\t\t\tfor (let i = 0; i < hooks.afterHandle.length; i++) {\n\t\t\t\t\tlet newResponse = hooks.afterHandle[i].fn(\n\t\t\t\t\t\tcontext as Context & {\n\t\t\t\t\t\t\tresponse: unknown\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t\tif (newResponse instanceof Promise)\n\t\t\t\t\t\tnewResponse = await newResponse\n\n\t\t\t\t\tconst result = mapEarlyResponse(newResponse, context.set)\n\t\t\t\t\tif (result !== undefined) {\n\t\t\t\t\t\tconst responseValidator =\n\t\t\t\t\t\t\tvalidator?.response?.[response.status]\n\n\t\t\t\t\t\tif (responseValidator?.Check(result) === false)\n\t\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t\t'response',\n\t\t\t\t\t\t\t\tresponseValidator,\n\t\t\t\t\t\t\t\tresult\n\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn result\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (context.set.cookie && cookieMeta?.sign) {\n\t\t\t\tconst secret = !cookieMeta.secrets\n\t\t\t\t\t? undefined\n\t\t\t\t\t: typeof cookieMeta.secrets === 'string'\n\t\t\t\t\t? cookieMeta.secrets\n\t\t\t\t\t: cookieMeta.secrets[0]\n\n\t\t\t\tif (cookieMeta.sign === true)\n\t\t\t\t\tfor (const [key, cookie] of Object.entries(\n\t\t\t\t\t\tcontext.set.cookie\n\t\t\t\t\t))\n\t\t\t\t\t\tcontext.set.cookie[key].value = await signCookie(\n\t\t\t\t\t\t\tcookie.value as any,\n\t\t\t\t\t\t\t'${secret}'\n\t\t\t\t\t\t)\n\t\t\t\telse {\n\t\t\t\t\t// @ts-expect-error private\n\t\t\t\t\tconst properties = validator?.cookie?.schema?.properties\n\n\t\t\t\t\tfor (const name of cookieMeta.sign) {\n\t\t\t\t\t\tif (!(name in properties))\n\t\t\t\t\t\t\tcontinue\n\n\t\t\t\t\t\tif (context.set.cookie[name]?.value) {\n\t\t\t\t\t\t\tcontext.set.cookie[name].value = await signCookie(\n\t\t\t\t\t\t\t\tcontext.set.cookie[name].value as any,\n\t\t\t\t\t\t\t\tsecret as any\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mapResponse(response, context.set)\n\t\t} catch (error) {\n\t\t\tif ((error as ElysiaErrors).status)\n\t\t\t\tset.status = (error as ElysiaErrors).status\n\n\t\t\t// @ts-expect-error private\n\t\t\treturn app.handleError(context, error)\n\t\t} finally {\n\t\t\tfor (const onResponse of app.event.onResponse)\n\t\t\t\tawait onResponse.fn(context)\n\t\t}\n\t}\n\nexport const createDynamicErrorHandler =\n\t(app: Elysia<any, any, any, any, any, any, any, any>) =>\n\tasync (context: Context, error: ElysiaErrors) => {\n\t\tconst errorContext = Object.assign(context, { error, code: error.code })\n\t\terrorContext.set = context.set\n\n\t\tfor (let i = 0; i < app.event.error.length; i++) {\n\t\t\tconst hook = app.event.error[i]\n\t\t\tlet response = hook.fn(errorContext as any)\n\t\t\tif (response instanceof Promise) response = await response\n\t\t\tif (response !== undefined && response !== null)\n\t\t\t\treturn mapResponse(response, context.set)\n\t\t}\n\n\t\treturn new Response(\n\t\t\ttypeof error.cause === 'string' ? error.cause : error.message,\n\t\t\t{\n\t\t\t\theaders: context.set.headers,\n\t\t\t\tstatus: error.status ?? 500\n\t\t\t}\n\t\t)\n\t}\n",
29
29
  "import {\n\tDateOptions,\n\tNumberOptions,\n\tTDate,\n\tTUnsafe,\n\tTypeRegistry\n} from '@sinclair/typebox'\nimport { TypeSystem } from '@sinclair/typebox/system'\nimport {\n\tType,\n\ttype SchemaOptions,\n\ttype TNull,\n\ttype TUnion,\n\ttype TSchema,\n\ttype TUndefined,\n\tTProperties,\n\tObjectOptions,\n\tTObject,\n\tTNumber,\n\tTBoolean,\n\tFormatRegistry\n} from '@sinclair/typebox'\n\nimport { type TypeCheck } from '@sinclair/typebox/compiler'\nimport { Value } from '@sinclair/typebox/value'\nimport { fullFormats } from './formats'\n\nimport type { CookieOptions } from './cookies'\nimport { ValidationError } from './error'\nimport type { MaybeArray } from './types'\n\nconst isISO8601 =\n\t/(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d:[0-5]\\d|Z))|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z))|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z))/\nconst isFormalDate =\n\t/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s\\d{2}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\sGMT(?:\\+|-)\\d{4}\\s\\([^)]+\\)/\nconst isShortenDate =\n\t/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\\s-](?:0?[1-9]|1[0-2])[/\\s-](?:19|20)\\d{2})|(?:(?:19|20)\\d{2}[/\\s-](?:0?[1-9]|1[0-2])[/\\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\\s[AP]M)?)?$/\n\nconst _validateDate = fullFormats.date\nconst _validateDateTime = fullFormats['date-time']\n\nTypeSystem.Format('date', (value: string) => {\n\t// Remove quote from stringified date\n\tconst temp = value.replace(/\"/g, '')\n\n\tif (\n\t\tisISO8601.test(temp) ||\n\t\tisFormalDate.test(temp) ||\n\t\tisShortenDate.test(temp) ||\n\t\t_validateDate(temp)\n\t) {\n\t\tconst date = new Date(temp)\n\t\tif (!Number.isNaN(date.getTime())) return true\n\t}\n\n\treturn false\n})\n\nTypeSystem.Format('date-time', (value: string) => {\n\t// Remove quote from stringified date\n\tconst temp = value.replace(/\"/g, '')\n\n\tif (\n\t\tisISO8601.test(temp) ||\n\t\tisFormalDate.test(temp) ||\n\t\tisShortenDate.test(temp) ||\n\t\t_validateDateTime(temp)\n\t) {\n\t\tconst date = new Date(temp)\n\t\tif (!Number.isNaN(date.getTime())) return true\n\t}\n\n\treturn false\n})\n\nObject.entries(fullFormats).forEach((formatEntry) => {\n\tconst [formatName, formatValue] = formatEntry\n\n\tif (!FormatRegistry.Has(formatName)) {\n\t\tif (formatValue instanceof RegExp)\n\t\t\tTypeSystem.Format(formatName, (value) => formatValue.test(value))\n\t\telse if (typeof formatValue === 'function')\n\t\t\tTypeSystem.Format(formatName, formatValue)\n\t}\n})\n\nconst t = Object.assign({}, Type)\n\nexport namespace ElysiaTypeOptions {\n\texport type Numeric = NumberOptions\n\n\texport type FileUnit = number | `${number}${'k' | 'm'}`\n\n\texport interface File extends SchemaOptions {\n\t\ttype?: MaybeArray<\n\t\t\t| (string & {})\n\t\t\t| 'image'\n\t\t\t| 'image/jpeg'\n\t\t\t| 'image/png'\n\t\t\t| 'image/gif'\n\t\t\t| 'image/tiff'\n\t\t\t| 'image/x-icon'\n\t\t\t| 'image/svg'\n\t\t\t| 'image/webp'\n\t\t\t| 'image/avif'\n\t\t\t| 'audio'\n\t\t\t| 'audio/mpeg'\n\t\t\t| 'audio/x-ms-wma'\n\t\t\t| 'audio/vnd.rn-realaudio'\n\t\t\t| 'audio/x-wav'\n\t\t\t| 'video'\n\t\t\t| 'video/mpeg'\n\t\t\t| 'video/mp4'\n\t\t\t| 'video/quicktime'\n\t\t\t| 'video/x-ms-wmv'\n\t\t\t| 'video/x-msvideo'\n\t\t\t| 'video/x-flv'\n\t\t\t| 'video/webm'\n\t\t\t| 'text'\n\t\t\t| 'text/css'\n\t\t\t| 'text/csv'\n\t\t\t| 'text/html'\n\t\t\t| 'text/javascript'\n\t\t\t| 'text/plain'\n\t\t\t| 'text/xml'\n\t\t\t| 'application'\n\t\t\t| 'application/ogg'\n\t\t\t| 'application/pdf'\n\t\t\t| 'application/xhtml'\n\t\t\t| 'application/html'\n\t\t\t| 'application/json'\n\t\t\t| 'application/ld+json'\n\t\t\t| 'application/xml'\n\t\t\t| 'application/zip'\n\t\t\t| 'font'\n\t\t\t| 'font/woff2'\n\t\t\t| 'font/woff'\n\t\t\t| 'font/ttf'\n\t\t\t| 'font/otf'\n\t\t>\n\t\tminSize?: FileUnit\n\t\tmaxSize?: FileUnit\n\t}\n\n\texport interface Files extends File {\n\t\tminItems?: number\n\t\tmaxItems?: number\n\t}\n\n\texport interface CookieValidatorOption<T extends Object = {}>\n\t\textends ObjectOptions,\n\t\t\tCookieOptions {\n\t\t/**\n\t\t * Secret key for signing cookie\n\t\t *\n\t\t * If array is passed, will use Key Rotation.\n\t\t *\n\t\t * Key rotation is when an encryption key is retired\n\t\t * and replaced by generating a new cryptographic key.\n\t\t */\n\t\tsecrets?: string | string[]\n\t\t/**\n\t\t * Specified cookie name to be signed globally\n\t\t */\n\t\tsign?: Readonly<(keyof T | (string & {}))[]>\n\t}\n}\n\nconst parseFileUnit = (size: ElysiaTypeOptions.FileUnit) => {\n\tif (typeof size === 'string')\n\t\tswitch (size.slice(-1)) {\n\t\t\tcase 'k':\n\t\t\t\treturn +size.slice(0, size.length - 1) * 1024\n\n\t\t\tcase 'm':\n\t\t\t\treturn +size.slice(0, size.length - 1) * 1048576\n\n\t\t\tdefault:\n\t\t\t\treturn +size\n\t\t}\n\n\treturn size\n}\n\nconst validateFile = (options: ElysiaTypeOptions.File, value: any) => {\n\tif (!(value instanceof Blob)) return false\n\n\tif (options.minSize && value.size < parseFileUnit(options.minSize))\n\t\treturn false\n\n\tif (options.maxSize && value.size > parseFileUnit(options.maxSize))\n\t\treturn false\n\n\tif (options.extension)\n\t\tif (typeof options.extension === 'string') {\n\t\t\tif (!value.type.startsWith(options.extension)) return false\n\t\t} else {\n\t\t\tfor (let i = 0; i < options.extension.length; i++)\n\t\t\t\tif (value.type.startsWith(options.extension[i])) return true\n\n\t\t\treturn false\n\t\t}\n\n\treturn true\n}\n\ntype ElysiaFile = (\n\toptions?: Partial<ElysiaTypeOptions.Files> | undefined\n) => TUnsafe<File>\n\nconst File: ElysiaFile =\n\t(TypeRegistry.Get('Files') as unknown as ElysiaFile) ??\n\tTypeSystem.Type<File, ElysiaTypeOptions.File>('File', validateFile)\n\ntype ElysiaFiles = (\n\toptions?: Partial<ElysiaTypeOptions.Files> | undefined\n) => TUnsafe<File[]>\n\nconst Files: ElysiaFiles =\n\t(TypeRegistry.Get('Files') as unknown as ElysiaFiles) ??\n\tTypeSystem.Type<File[], ElysiaTypeOptions.Files>(\n\t\t'Files',\n\t\t(options, value) => {\n\t\t\tif (!Array.isArray(value)) return validateFile(options, value)\n\n\t\t\tif (options.minItems && value.length < options.minItems)\n\t\t\t\treturn false\n\n\t\t\tif (options.maxItems && value.length > options.maxItems)\n\t\t\t\treturn false\n\n\t\t\tfor (let i = 0; i < value.length; i++)\n\t\t\t\tif (!validateFile(options, value[i])) return false\n\n\t\t\treturn true\n\t\t}\n\t)\n\nif (!FormatRegistry.Has('numeric'))\n\tFormatRegistry.Set('numeric', (value) => !!value && !isNaN(+value))\n\nif (!FormatRegistry.Has('boolean'))\n\tFormatRegistry.Set(\n\t\t'boolean',\n\t\t(value) => value === 'true' || value === 'false'\n\t)\n\nif (!FormatRegistry.Has('ObjectString'))\n\tFormatRegistry.Set('ObjectString', (value) => {\n\t\tlet start = value.charCodeAt(0)\n\n\t\t// If starts with ' ', '\\t', '\\n', then trim first\n\t\tif (start === 9 || start === 10 || start === 32)\n\t\t\tstart = value.trimStart().charCodeAt(0)\n\n\t\tif (start !== 123 && start !== 91) return false\n\n\t\ttry {\n\t\t\tJSON.parse(value)\n\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t})\n\nexport const ElysiaType = {\n\tNumeric: (property?: NumberOptions) => {\n\t\tconst schema = Type.Number(property)\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union(\n\t\t\t\t\t[\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'numeric',\n\t\t\t\t\t\t\tdefault: 0\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tt.Number(property)\n\t\t\t\t\t],\n\t\t\t\t\tproperty\n\t\t\t\t)\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tconst number = +value\n\t\t\t\tif (isNaN(number)) return value\n\n\t\t\t\tif (property && !Value.Check(schema, number))\n\t\t\t\t\tthrow new ValidationError('property', schema, number)\n\n\t\t\t\treturn number\n\t\t\t})\n\t\t\t.Encode((value) => value) as any as TNumber\n\t},\n\tDate: (property?: DateOptions) => {\n\t\tconst schema = Type.Date(property)\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union(\n\t\t\t\t\t[\n\t\t\t\t\t\tType.Date(property),\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'date',\n\t\t\t\t\t\t\tdefault: new Date().toISOString()\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'date-time',\n\t\t\t\t\t\t\tdefault: new Date().toISOString()\n\t\t\t\t\t\t})\n\t\t\t\t\t],\n\t\t\t\t\tproperty\n\t\t\t\t)\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tif (value instanceof Date) return value\n\n\t\t\t\tconst date = new Date(value)\n\n\t\t\t\tif (!Value.Check(schema, date))\n\t\t\t\t\tthrow new ValidationError('property', schema, date)\n\n\t\t\t\treturn date\n\t\t\t})\n\t\t\t.Encode((value) => {\n\t\t\t\tif (typeof value === 'string') return new Date(value)\n\n\t\t\t\treturn value\n\t\t\t}) as any as TDate\n\t},\n\tBooleanString: (property?: SchemaOptions) => {\n\t\tconst schema = Type.Boolean(property)\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union(\n\t\t\t\t\t[\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'boolean',\n\t\t\t\t\t\t\tdefault: false\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tt.Boolean(property)\n\t\t\t\t\t],\n\t\t\t\t\tproperty\n\t\t\t\t)\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tif (typeof value === 'string') return value === 'true'\n\n\t\t\t\tif (property && !Value.Check(schema, value))\n\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\n\t\t\t\treturn value\n\t\t\t})\n\t\t\t.Encode((value) => value) as any as TBoolean\n\t},\n\tObjectString: <T extends TProperties = {}>(\n\t\tproperties: T = {} as T,\n\t\toptions?: ObjectOptions\n\t) => {\n\t\tconst schema = t.Object(properties, options)\n\t\tconst defaultValue = JSON.stringify(Value.Create(schema))\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union([\n\t\t\t\t\tt.String({\n\t\t\t\t\t\tformat: 'ObjectString',\n\t\t\t\t\t\tdefault: defaultValue\n\t\t\t\t\t}),\n\t\t\t\t\tschema\n\t\t\t\t])\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvalue = JSON.parse(value as string)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!Value.Check(schema, value))\n\t\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\n\t\t\t\t\treturn value\n\t\t\t\t}\n\n\t\t\t\treturn value\n\t\t\t})\n\t\t\t.Encode((value) => {\n\t\t\t\tif (typeof value === 'string')\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvalue = JSON.parse(value as string)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\t\t\t\t\t}\n\n\t\t\t\tif (!Value.Check(schema, value))\n\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\n\t\t\t\treturn JSON.stringify(value)\n\t\t\t}) as any as TObject<T>\n\t},\n\tFile,\n\tFiles: (options: ElysiaTypeOptions.Files = {}) =>\n\t\tt\n\t\t\t.Transform(Files(options))\n\t\t\t.Decode((value) => {\n\t\t\t\tif (Array.isArray(value)) return value\n\t\t\t\treturn [value]\n\t\t\t})\n\t\t\t.Encode((value) => value),\n\tNullable: <T extends TSchema>(schema: T): TUnion<[T, TNull]> =>\n\t\tt.Union([t.Null(), schema]) as any,\n\t/**\n\t * Allow Optional, Nullable and Undefined\n\t */\n\tMaybeEmpty: <T extends TSchema>(schema: T): TUnion<[T, TUndefined]> =>\n\t\tt.Union([t.Null(), t.Undefined(), schema]) as any,\n\tCookie: <T extends TProperties>(\n\t\tproperties: T,\n\t\t{\n\t\t\tdomain,\n\t\t\texpires,\n\t\t\thttpOnly,\n\t\t\tmaxAge,\n\t\t\tpath,\n\t\t\tpriority,\n\t\t\tsameSite,\n\t\t\tsecure,\n\t\t\tsecrets,\n\t\t\tsign,\n\t\t\t...options\n\t\t}: ElysiaTypeOptions.CookieValidatorOption<T> = {}\n\t) => {\n\t\tconst v = t.Object(properties, options)\n\n\t\tv.config = {\n\t\t\tdomain,\n\t\t\texpires,\n\t\t\thttpOnly,\n\t\t\tmaxAge,\n\t\t\tpath,\n\t\t\tpriority,\n\t\t\tsameSite,\n\t\t\tsecure,\n\t\t\tsecrets,\n\t\t\tsign\n\t\t}\n\n\t\treturn v\n\t}\n} as const\n\nexport type TCookie = (typeof ElysiaType)['Cookie']\n\ndeclare module '@sinclair/typebox' {\n\tinterface JavaScriptTypeBuilder {\n\t\tBooleanString: typeof ElysiaType.BooleanString\n\t\tObjectString: typeof ElysiaType.ObjectString\n\t\t// @ts-ignore\n\t\tNumeric: typeof ElysiaType.Numeric\n\t\t// @ts-ignore\n\t\tFile: typeof ElysiaType.File\n\t\t// @ts-ignore\n\t\tFiles: typeof ElysiaType.Files\n\t\tNullable: typeof ElysiaType.Nullable\n\t\tMaybeEmpty: typeof ElysiaType.MaybeEmpty\n\t\tCookie: typeof ElysiaType.Cookie\n\t}\n\n\tinterface SchemaOptions {\n\t\terror?:\n\t\t\t| string\n\t\t\t| ((\n\t\t\t\t\ttype: string,\n\t\t\t\t\tvalidator: TypeCheck<any>,\n\t\t\t\t\tvalue: unknown\n\t\t\t ) => string | void)\n\t}\n}\n\n/**\n * A Boolean string\n *\n * Will be parse to Boolean\n */\nt.BooleanString = ElysiaType.BooleanString\n\nt.ObjectString = ElysiaType.ObjectString\n\n/**\n * A Numeric string\n *\n * Will be parse to Number\n */\nt.Numeric = ElysiaType.Numeric\n\nt.File = (arg = {}) =>\n\tElysiaType.File({\n\t\tdefault: 'File',\n\t\t...arg,\n\t\textension: arg?.type,\n\t\ttype: 'string',\n\t\tformat: 'binary'\n\t})\n\nt.Files = (arg = {}) =>\n\tElysiaType.Files({\n\t\t...arg,\n\t\telysiaMeta: 'Files',\n\t\tdefault: 'Files',\n\t\textension: arg?.type,\n\t\ttype: 'array',\n\t\titems: {\n\t\t\t...arg,\n\t\t\tdefault: 'Files',\n\t\t\ttype: 'string',\n\t\t\tformat: 'binary'\n\t\t}\n\t})\n\nt.Nullable = (schema) => ElysiaType.Nullable(schema)\nt.MaybeEmpty = ElysiaType.MaybeEmpty\n\nt.Cookie = ElysiaType.Cookie\nt.Date = ElysiaType.Date\n\nexport { t }\n\nexport {\n\tTypeSystemPolicy,\n\tTypeSystem,\n\tTypeSystemDuplicateFormat,\n\tTypeSystemDuplicateTypeKind\n} from '@sinclair/typebox/system'\nexport { TypeCompiler, TypeCheck } from '@sinclair/typebox/compiler'\n\n// type Template =\n// \t| string\n// \t| number\n// \t| bigint\n// \t| boolean\n// \t| StringConstructor\n// \t| NumberConstructor\n// \t| undefined\n\n// type Join<A> = A extends Readonly<[infer First, ...infer Rest]>\n// \t? (\n// \t\t\tFirst extends Readonly<Template[]>\n// \t\t\t\t? First[number]\n// \t\t\t\t: First extends StringConstructor\n// \t\t\t\t? string\n// \t\t\t\t: First extends NumberConstructor\n// \t\t\t\t? `${number}`\n// \t\t\t\t: First\n// \t ) extends infer A\n// \t\t? Rest extends []\n// \t\t\t? A extends undefined\n// \t\t\t\t? NonNullable<A> | ''\n// \t\t\t\t: A\n// \t\t\t: // @ts-ignore\n// \t\t\tA extends undefined\n// \t\t\t? `${NonNullable<A>}${Join<Rest>}` | ''\n// \t\t\t: // @ts-ignore\n// \t\t\t `${A}${Join<Rest>}`\n// \t\t: ''\n// \t: ''\n\n// const template = <\n// \tconst T extends Readonly<(Template | Readonly<Template[]>)[]>\n// >(\n// \t...p: T\n// ): Join<T> => {\n// \treturn a as any\n// }\n\n// const create =\n// \t<const T extends string>(t: T): ((t: T) => void) =>\n// \t(t) =>\n// \t\tt\n\n// const optional = <\n// \tconst T extends Readonly<(Template | Readonly<Template[]>)[]>\n// >(\n// \t...p: T\n// ): T | undefined => {\n// \treturn undefined\n// }\n\n// template.optional = optional\n\n// const hi = create(\n// \ttemplate(\n// \t\t['seminar', 'millennium'],\n// \t\t':',\n// \t\t['Rio', 'Yuuka', 'Noa', 'Koyuki'],\n// \t\ttemplate.optional(template(',', ['Rio', 'Yuuka', 'Noa', 'Koyuki'])),\n// \t\ttemplate.optional(template(',', ['Rio', 'Yuuka', 'Noa', 'Koyuki'])),\n// \t\ttemplate.optional(template(',', ['Rio', 'Yuuka', 'Noa', 'Koyuki']))\n// \t)\n// )\n\n// hi(`seminar:Noa,Koyuki,Yuuka`)\n\n// const a = TypeCompiler.Compile(t.String())\n\n// console.log(v.Decode.toString())\n\n// const T = t.Transform(v.schema)\n// \t.Decode((value) => new Date(value)) // required: number to Date\n// \t.Encode((value) => value.getTime()) // required: Date to number\n\n// const decoded = Value.Decode(T, 0) // const decoded = Date(1970-01-01T00:00:00.000Z)\n// const encoded = Value.Encode(T, decoded)\n",
30
30
  "/**\n * ? Fork of ajv-formats without ajv as dependencies\n *\n * @see https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts\n **/\n\n/* eslint-disable no-control-regex */\nexport type FormatName =\n\t| 'date'\n\t| 'time'\n\t| 'date-time'\n\t| 'iso-time'\n\t| 'iso-date-time'\n\t| 'duration'\n\t| 'uri'\n\t| 'uri-reference'\n\t| 'uri-template'\n\t| 'url'\n\t| 'email'\n\t| 'hostname'\n\t| 'ipv4'\n\t| 'ipv6'\n\t| 'regex'\n\t| 'uuid'\n\t| 'json-pointer'\n\t| 'json-pointer-uri-fragment'\n\t| 'relative-json-pointer'\n\t| 'byte'\n\t| 'int32'\n\t| 'int64'\n\t| 'float'\n\t| 'double'\n\t| 'password'\n\t| 'binary'\n\nexport const fullFormats = {\n\t// date: http://tools.ietf.org/html/rfc3339#section-5.6\n\tdate,\n\t// date-time: http://tools.ietf.org/html/rfc3339#section-5.6\n\ttime: getTime(true),\n\t'date-time': getDateTime(true),\n\t'iso-time': getTime(false),\n\t'iso-date-time': getDateTime(false),\n\t// duration: https://tools.ietf.org/html/rfc3339#appendix-A\n\tduration:\n\t\t/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/,\n\turi,\n\t'uri-reference':\n\t\t/^(?:[a-z][a-z0-9+\\-.]*:)?(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){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0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i,\n\t// For the source: https://gist.github.com/dperini/729294\n\t// For test cases: https://mathiasbynens.be/demo/url-regex\n\turl: /^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu,\n\temail: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,\n\thostname:\n\t\t/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i,\n\t// optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html\n\tipv4: /^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/,\n\tipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))$/i,\n\tregex,\n\t// uuid: http://tools.ietf.org/html/rfc4122\n\tuuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,\n\t// JSON-pointer: https://tools.ietf.org/html/rfc6901\n\t// uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A\n\t'json-pointer': /^(?:\\/(?:[^~/]|~0|~1)*)*$/,\n\t'json-pointer-uri-fragment':\n\t\t/^#(?:\\/(?:[a-z0-9_\\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,\n\t// relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00\n\t'relative-json-pointer': /^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/,\n\t// the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types\n\t// byte: https://github.com/miguelmota/is-base64\n\tbyte,\n\t// signed 32 bit integer\n\tint32: { type: 'number', validate: validateInt32 },\n\t// signed 64 bit integer\n\tint64: { type: 'number', validate: validateInt64 },\n\t// C-type float\n\tfloat: { type: 'number', validate: validateNumber },\n\t// C-type double\n\tdouble: { type: 'number', validate: validateNumber },\n\t// hint to the UI to hide input strings\n\tpassword: true,\n\t// unchecked string payload\n\tbinary: true\n} as const\n\nfunction isLeapYear(year: number): boolean {\n\t// https://tools.ietf.org/html/rfc3339#appendix-C\n\treturn year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)\n}\n\nconst DATE = /^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$/\nconst DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\nfunction date(str: string): boolean {\n\t// full-date from http://tools.ietf.org/html/rfc3339#section-5.6\n\tconst matches: string[] | null = DATE.exec(str)\n\tif (!matches) return false\n\tconst year: number = +matches[1]\n\tconst month: number = +matches[2]\n\tconst day: number = +matches[3]\n\treturn (\n\t\tmonth >= 1 &&\n\t\tmonth <= 12 &&\n\t\tday >= 1 &&\n\t\tday <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month])\n\t)\n}\n\nconst TIME = /^(\\d\\d):(\\d\\d):(\\d\\d(?:\\.\\d+)?)(z|([+-])(\\d\\d)(?::?(\\d\\d))?)?$/i\n\nfunction getTime(strictTimeZone?: boolean): (str: string) => boolean {\n\treturn function time(str: string): boolean {\n\t\tconst matches: string[] | null = TIME.exec(str)\n\t\tif (!matches) return false\n\t\tconst hr: number = +matches[1]\n\t\tconst min: number = +matches[2]\n\t\tconst sec: number = +matches[3]\n\t\tconst tz: string | undefined = matches[4]\n\t\tconst tzSign: number = matches[5] === '-' ? -1 : 1\n\t\tconst tzH: number = +(matches[6] || 0)\n\t\tconst tzM: number = +(matches[7] || 0)\n\t\tif (tzH > 23 || tzM > 59 || (strictTimeZone && !tz)) return false\n\t\tif (hr <= 23 && min <= 59 && sec < 60) return true\n\t\t// leap second\n\t\tconst utcMin = min - tzM * tzSign\n\t\tconst utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0)\n\t\treturn (\n\t\t\t(utcHr === 23 || utcHr === -1) &&\n\t\t\t(utcMin === 59 || utcMin === -1) &&\n\t\t\tsec < 61\n\t\t)\n\t}\n}\n\nconst DATE_TIME_SEPARATOR = /t|\\s/i\nfunction getDateTime(strictTimeZone?: boolean): (str: string) => boolean {\n\tconst time = getTime(strictTimeZone)\n\n\treturn function date_time(str: string): boolean {\n\t\t// http://tools.ietf.org/html/rfc3339#section-5.6\n\t\tconst dateTime: string[] = str.split(DATE_TIME_SEPARATOR)\n\t\treturn dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1])\n\t}\n}\n\nconst NOT_URI_FRAGMENT = /\\/|:/\nconst URI =\n\t/^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\\?(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i\n\nfunction uri(str: string): boolean {\n\t// http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required \".\"\n\treturn NOT_URI_FRAGMENT.test(str) && URI.test(str)\n}\n\nconst BYTE =\n\t/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm\n\nfunction byte(str: string): boolean {\n\tBYTE.lastIndex = 0\n\treturn BYTE.test(str)\n}\n\nconst MIN_INT32 = -(2 ** 31)\nconst MAX_INT32 = 2 ** 31 - 1\n\nfunction validateInt32(value: number): boolean {\n\treturn Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32\n}\n\nfunction validateInt64(value: number): boolean {\n\t// JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64\n\treturn Number.isInteger(value)\n}\n\nfunction validateNumber(): boolean {\n\treturn true\n}\n\nconst Z_ANCHOR = /[^\\\\]\\\\Z/\nfunction regex(str: string): boolean {\n\tif (Z_ANCHOR.test(str)) return false\n\ttry {\n\t\tnew RegExp(str)\n\t\treturn true\n\t} catch (e) {\n\t\treturn false\n\t}\n}\n\n/**\n * @license\n * \n * MIT License\n * \n * Copyright (c) 2020 Evgeny Poberezkin\n * \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n * \n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n",
31
31
  "import {\n\tDateOptions,\n\tNumberOptions,\n\tTDate,\n\tTUnsafe,\n\tTypeRegistry\n} from '@sinclair/typebox'\nimport { TypeSystem } from '@sinclair/typebox/system'\nimport {\n\tType,\n\ttype SchemaOptions,\n\ttype TNull,\n\ttype TUnion,\n\ttype TSchema,\n\ttype TUndefined,\n\tTProperties,\n\tObjectOptions,\n\tTObject,\n\tTNumber,\n\tTBoolean,\n\tFormatRegistry\n} from '@sinclair/typebox'\n\nimport { type TypeCheck } from '@sinclair/typebox/compiler'\nimport { Value } from '@sinclair/typebox/value'\nimport { fullFormats } from './formats'\n\nimport type { CookieOptions } from './cookies'\nimport { ValidationError } from './error'\nimport type { MaybeArray } from './types'\n\nconst isISO8601 =\n\t/(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d:[0-5]\\d|Z))|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z))|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z))/\nconst isFormalDate =\n\t/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s\\d{2}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\sGMT(?:\\+|-)\\d{4}\\s\\([^)]+\\)/\nconst isShortenDate =\n\t/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\\s-](?:0?[1-9]|1[0-2])[/\\s-](?:19|20)\\d{2})|(?:(?:19|20)\\d{2}[/\\s-](?:0?[1-9]|1[0-2])[/\\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\\s[AP]M)?)?$/\n\nconst _validateDate = fullFormats.date\nconst _validateDateTime = fullFormats['date-time']\n\nTypeSystem.Format('date', (value: string) => {\n\t// Remove quote from stringified date\n\tconst temp = value.replace(/\"/g, '')\n\n\tif (\n\t\tisISO8601.test(temp) ||\n\t\tisFormalDate.test(temp) ||\n\t\tisShortenDate.test(temp) ||\n\t\t_validateDate(temp)\n\t) {\n\t\tconst date = new Date(temp)\n\t\tif (!Number.isNaN(date.getTime())) return true\n\t}\n\n\treturn false\n})\n\nTypeSystem.Format('date-time', (value: string) => {\n\t// Remove quote from stringified date\n\tconst temp = value.replace(/\"/g, '')\n\n\tif (\n\t\tisISO8601.test(temp) ||\n\t\tisFormalDate.test(temp) ||\n\t\tisShortenDate.test(temp) ||\n\t\t_validateDateTime(temp)\n\t) {\n\t\tconst date = new Date(temp)\n\t\tif (!Number.isNaN(date.getTime())) return true\n\t}\n\n\treturn false\n})\n\nObject.entries(fullFormats).forEach((formatEntry) => {\n\tconst [formatName, formatValue] = formatEntry\n\n\tif (!FormatRegistry.Has(formatName)) {\n\t\tif (formatValue instanceof RegExp)\n\t\t\tTypeSystem.Format(formatName, (value) => formatValue.test(value))\n\t\telse if (typeof formatValue === 'function')\n\t\t\tTypeSystem.Format(formatName, formatValue)\n\t}\n})\n\nconst t = Object.assign({}, Type)\n\nexport namespace ElysiaTypeOptions {\n\texport type Numeric = NumberOptions\n\n\texport type FileUnit = number | `${number}${'k' | 'm'}`\n\n\texport interface File extends SchemaOptions {\n\t\ttype?: MaybeArray<\n\t\t\t| (string & {})\n\t\t\t| 'image'\n\t\t\t| 'image/jpeg'\n\t\t\t| 'image/png'\n\t\t\t| 'image/gif'\n\t\t\t| 'image/tiff'\n\t\t\t| 'image/x-icon'\n\t\t\t| 'image/svg'\n\t\t\t| 'image/webp'\n\t\t\t| 'image/avif'\n\t\t\t| 'audio'\n\t\t\t| 'audio/mpeg'\n\t\t\t| 'audio/x-ms-wma'\n\t\t\t| 'audio/vnd.rn-realaudio'\n\t\t\t| 'audio/x-wav'\n\t\t\t| 'video'\n\t\t\t| 'video/mpeg'\n\t\t\t| 'video/mp4'\n\t\t\t| 'video/quicktime'\n\t\t\t| 'video/x-ms-wmv'\n\t\t\t| 'video/x-msvideo'\n\t\t\t| 'video/x-flv'\n\t\t\t| 'video/webm'\n\t\t\t| 'text'\n\t\t\t| 'text/css'\n\t\t\t| 'text/csv'\n\t\t\t| 'text/html'\n\t\t\t| 'text/javascript'\n\t\t\t| 'text/plain'\n\t\t\t| 'text/xml'\n\t\t\t| 'application'\n\t\t\t| 'application/ogg'\n\t\t\t| 'application/pdf'\n\t\t\t| 'application/xhtml'\n\t\t\t| 'application/html'\n\t\t\t| 'application/json'\n\t\t\t| 'application/ld+json'\n\t\t\t| 'application/xml'\n\t\t\t| 'application/zip'\n\t\t\t| 'font'\n\t\t\t| 'font/woff2'\n\t\t\t| 'font/woff'\n\t\t\t| 'font/ttf'\n\t\t\t| 'font/otf'\n\t\t>\n\t\tminSize?: FileUnit\n\t\tmaxSize?: FileUnit\n\t}\n\n\texport interface Files extends File {\n\t\tminItems?: number\n\t\tmaxItems?: number\n\t}\n\n\texport interface CookieValidatorOption<T extends Object = {}>\n\t\textends ObjectOptions,\n\t\t\tCookieOptions {\n\t\t/**\n\t\t * Secret key for signing cookie\n\t\t *\n\t\t * If array is passed, will use Key Rotation.\n\t\t *\n\t\t * Key rotation is when an encryption key is retired\n\t\t * and replaced by generating a new cryptographic key.\n\t\t */\n\t\tsecrets?: string | string[]\n\t\t/**\n\t\t * Specified cookie name to be signed globally\n\t\t */\n\t\tsign?: Readonly<(keyof T | (string & {}))[]>\n\t}\n}\n\nconst parseFileUnit = (size: ElysiaTypeOptions.FileUnit) => {\n\tif (typeof size === 'string')\n\t\tswitch (size.slice(-1)) {\n\t\t\tcase 'k':\n\t\t\t\treturn +size.slice(0, size.length - 1) * 1024\n\n\t\t\tcase 'm':\n\t\t\t\treturn +size.slice(0, size.length - 1) * 1048576\n\n\t\t\tdefault:\n\t\t\t\treturn +size\n\t\t}\n\n\treturn size\n}\n\nconst validateFile = (options: ElysiaTypeOptions.File, value: any) => {\n\tif (!(value instanceof Blob)) return false\n\n\tif (options.minSize && value.size < parseFileUnit(options.minSize))\n\t\treturn false\n\n\tif (options.maxSize && value.size > parseFileUnit(options.maxSize))\n\t\treturn false\n\n\tif (options.extension)\n\t\tif (typeof options.extension === 'string') {\n\t\t\tif (!value.type.startsWith(options.extension)) return false\n\t\t} else {\n\t\t\tfor (let i = 0; i < options.extension.length; i++)\n\t\t\t\tif (value.type.startsWith(options.extension[i])) return true\n\n\t\t\treturn false\n\t\t}\n\n\treturn true\n}\n\ntype ElysiaFile = (\n\toptions?: Partial<ElysiaTypeOptions.Files> | undefined\n) => TUnsafe<File>\n\nconst File: ElysiaFile =\n\t(TypeRegistry.Get('Files') as unknown as ElysiaFile) ??\n\tTypeSystem.Type<File, ElysiaTypeOptions.File>('File', validateFile)\n\ntype ElysiaFiles = (\n\toptions?: Partial<ElysiaTypeOptions.Files> | undefined\n) => TUnsafe<File[]>\n\nconst Files: ElysiaFiles =\n\t(TypeRegistry.Get('Files') as unknown as ElysiaFiles) ??\n\tTypeSystem.Type<File[], ElysiaTypeOptions.Files>(\n\t\t'Files',\n\t\t(options, value) => {\n\t\t\tif (!Array.isArray(value)) return validateFile(options, value)\n\n\t\t\tif (options.minItems && value.length < options.minItems)\n\t\t\t\treturn false\n\n\t\t\tif (options.maxItems && value.length > options.maxItems)\n\t\t\t\treturn false\n\n\t\t\tfor (let i = 0; i < value.length; i++)\n\t\t\t\tif (!validateFile(options, value[i])) return false\n\n\t\t\treturn true\n\t\t}\n\t)\n\nif (!FormatRegistry.Has('numeric'))\n\tFormatRegistry.Set('numeric', (value) => !!value && !isNaN(+value))\n\nif (!FormatRegistry.Has('boolean'))\n\tFormatRegistry.Set(\n\t\t'boolean',\n\t\t(value) => value === 'true' || value === 'false'\n\t)\n\nif (!FormatRegistry.Has('ObjectString'))\n\tFormatRegistry.Set('ObjectString', (value) => {\n\t\tlet start = value.charCodeAt(0)\n\n\t\t// If starts with ' ', '\\t', '\\n', then trim first\n\t\tif (start === 9 || start === 10 || start === 32)\n\t\t\tstart = value.trimStart().charCodeAt(0)\n\n\t\tif (start !== 123 && start !== 91) return false\n\n\t\ttry {\n\t\t\tJSON.parse(value)\n\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t})\n\nexport const ElysiaType = {\n\tNumeric: (property?: NumberOptions) => {\n\t\tconst schema = Type.Number(property)\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union(\n\t\t\t\t\t[\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'numeric',\n\t\t\t\t\t\t\tdefault: 0\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tt.Number(property)\n\t\t\t\t\t],\n\t\t\t\t\tproperty\n\t\t\t\t)\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tconst number = +value\n\t\t\t\tif (isNaN(number)) return value\n\n\t\t\t\tif (property && !Value.Check(schema, number))\n\t\t\t\t\tthrow new ValidationError('property', schema, number)\n\n\t\t\t\treturn number\n\t\t\t})\n\t\t\t.Encode((value) => value) as any as TNumber\n\t},\n\tDate: (property?: DateOptions) => {\n\t\tconst schema = Type.Date(property)\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union(\n\t\t\t\t\t[\n\t\t\t\t\t\tType.Date(property),\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'date',\n\t\t\t\t\t\t\tdefault: new Date().toISOString()\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'date-time',\n\t\t\t\t\t\t\tdefault: new Date().toISOString()\n\t\t\t\t\t\t})\n\t\t\t\t\t],\n\t\t\t\t\tproperty\n\t\t\t\t)\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tif (value instanceof Date) return value\n\n\t\t\t\tconst date = new Date(value)\n\n\t\t\t\tif (!Value.Check(schema, date))\n\t\t\t\t\tthrow new ValidationError('property', schema, date)\n\n\t\t\t\treturn date\n\t\t\t})\n\t\t\t.Encode((value) => {\n\t\t\t\tif (typeof value === 'string') return new Date(value)\n\n\t\t\t\treturn value\n\t\t\t}) as any as TDate\n\t},\n\tBooleanString: (property?: SchemaOptions) => {\n\t\tconst schema = Type.Boolean(property)\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union(\n\t\t\t\t\t[\n\t\t\t\t\t\tt.String({\n\t\t\t\t\t\t\tformat: 'boolean',\n\t\t\t\t\t\t\tdefault: false\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tt.Boolean(property)\n\t\t\t\t\t],\n\t\t\t\t\tproperty\n\t\t\t\t)\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tif (typeof value === 'string') return value === 'true'\n\n\t\t\t\tif (property && !Value.Check(schema, value))\n\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\n\t\t\t\treturn value\n\t\t\t})\n\t\t\t.Encode((value) => value) as any as TBoolean\n\t},\n\tObjectString: <T extends TProperties = {}>(\n\t\tproperties: T = {} as T,\n\t\toptions?: ObjectOptions\n\t) => {\n\t\tconst schema = t.Object(properties, options)\n\t\tconst defaultValue = JSON.stringify(Value.Create(schema))\n\n\t\treturn t\n\t\t\t.Transform(\n\t\t\t\tt.Union([\n\t\t\t\t\tt.String({\n\t\t\t\t\t\tformat: 'ObjectString',\n\t\t\t\t\t\tdefault: defaultValue\n\t\t\t\t\t}),\n\t\t\t\t\tschema\n\t\t\t\t])\n\t\t\t)\n\t\t\t.Decode((value) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvalue = JSON.parse(value as string)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!Value.Check(schema, value))\n\t\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\n\t\t\t\t\treturn value\n\t\t\t\t}\n\n\t\t\t\treturn value\n\t\t\t})\n\t\t\t.Encode((value) => {\n\t\t\t\tif (typeof value === 'string')\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvalue = JSON.parse(value as string)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\t\t\t\t\t}\n\n\t\t\t\tif (!Value.Check(schema, value))\n\t\t\t\t\tthrow new ValidationError('property', schema, value)\n\n\t\t\t\treturn JSON.stringify(value)\n\t\t\t}) as any as TObject<T>\n\t},\n\tFile,\n\tFiles: (options: ElysiaTypeOptions.Files = {}) =>\n\t\tt\n\t\t\t.Transform(Files(options))\n\t\t\t.Decode((value) => {\n\t\t\t\tif (Array.isArray(value)) return value\n\t\t\t\treturn [value]\n\t\t\t})\n\t\t\t.Encode((value) => value),\n\tNullable: <T extends TSchema>(schema: T): TUnion<[T, TNull]> =>\n\t\tt.Union([t.Null(), schema]) as any,\n\t/**\n\t * Allow Optional, Nullable and Undefined\n\t */\n\tMaybeEmpty: <T extends TSchema>(schema: T): TUnion<[T, TUndefined]> =>\n\t\tt.Union([t.Null(), t.Undefined(), schema]) as any,\n\tCookie: <T extends TProperties>(\n\t\tproperties: T,\n\t\t{\n\t\t\tdomain,\n\t\t\texpires,\n\t\t\thttpOnly,\n\t\t\tmaxAge,\n\t\t\tpath,\n\t\t\tpriority,\n\t\t\tsameSite,\n\t\t\tsecure,\n\t\t\tsecrets,\n\t\t\tsign,\n\t\t\t...options\n\t\t}: ElysiaTypeOptions.CookieValidatorOption<T> = {}\n\t) => {\n\t\tconst v = t.Object(properties, options)\n\n\t\tv.config = {\n\t\t\tdomain,\n\t\t\texpires,\n\t\t\thttpOnly,\n\t\t\tmaxAge,\n\t\t\tpath,\n\t\t\tpriority,\n\t\t\tsameSite,\n\t\t\tsecure,\n\t\t\tsecrets,\n\t\t\tsign\n\t\t}\n\n\t\treturn v\n\t}\n} as const\n\nexport type TCookie = (typeof ElysiaType)['Cookie']\n\ndeclare module '@sinclair/typebox' {\n\tinterface JavaScriptTypeBuilder {\n\t\tBooleanString: typeof ElysiaType.BooleanString\n\t\tObjectString: typeof ElysiaType.ObjectString\n\t\t// @ts-ignore\n\t\tNumeric: typeof ElysiaType.Numeric\n\t\t// @ts-ignore\n\t\tFile: typeof ElysiaType.File\n\t\t// @ts-ignore\n\t\tFiles: typeof ElysiaType.Files\n\t\tNullable: typeof ElysiaType.Nullable\n\t\tMaybeEmpty: typeof ElysiaType.MaybeEmpty\n\t\tCookie: typeof ElysiaType.Cookie\n\t}\n\n\tinterface SchemaOptions {\n\t\terror?:\n\t\t\t| string\n\t\t\t| ((\n\t\t\t\t\ttype: string,\n\t\t\t\t\tvalidator: TypeCheck<any>,\n\t\t\t\t\tvalue: unknown\n\t\t\t ) => string | void)\n\t}\n}\n\n/**\n * A Boolean string\n *\n * Will be parse to Boolean\n */\nt.BooleanString = ElysiaType.BooleanString\n\nt.ObjectString = ElysiaType.ObjectString\n\n/**\n * A Numeric string\n *\n * Will be parse to Number\n */\nt.Numeric = ElysiaType.Numeric\n\nt.File = (arg = {}) =>\n\tElysiaType.File({\n\t\tdefault: 'File',\n\t\t...arg,\n\t\textension: arg?.type,\n\t\ttype: 'string',\n\t\tformat: 'binary'\n\t})\n\nt.Files = (arg = {}) =>\n\tElysiaType.Files({\n\t\t...arg,\n\t\telysiaMeta: 'Files',\n\t\tdefault: 'Files',\n\t\textension: arg?.type,\n\t\ttype: 'array',\n\t\titems: {\n\t\t\t...arg,\n\t\t\tdefault: 'Files',\n\t\t\ttype: 'string',\n\t\t\tformat: 'binary'\n\t\t}\n\t})\n\nt.Nullable = (schema) => ElysiaType.Nullable(schema)\nt.MaybeEmpty = ElysiaType.MaybeEmpty\n\nt.Cookie = ElysiaType.Cookie\nt.Date = ElysiaType.Date\n\nexport { t }\n\nexport {\n\tTypeSystemPolicy,\n\tTypeSystem,\n\tTypeSystemDuplicateFormat,\n\tTypeSystemDuplicateTypeKind\n} from '@sinclair/typebox/system'\nexport { TypeCompiler, TypeCheck } from '@sinclair/typebox/compiler'\n\n// type Template =\n// \t| string\n// \t| number\n// \t| bigint\n// \t| boolean\n// \t| StringConstructor\n// \t| NumberConstructor\n// \t| undefined\n\n// type Join<A> = A extends Readonly<[infer First, ...infer Rest]>\n// \t? (\n// \t\t\tFirst extends Readonly<Template[]>\n// \t\t\t\t? First[number]\n// \t\t\t\t: First extends StringConstructor\n// \t\t\t\t? string\n// \t\t\t\t: First extends NumberConstructor\n// \t\t\t\t? `${number}`\n// \t\t\t\t: First\n// \t ) extends infer A\n// \t\t? Rest extends []\n// \t\t\t? A extends undefined\n// \t\t\t\t? NonNullable<A> | ''\n// \t\t\t\t: A\n// \t\t\t: // @ts-ignore\n// \t\t\tA extends undefined\n// \t\t\t? `${NonNullable<A>}${Join<Rest>}` | ''\n// \t\t\t: // @ts-ignore\n// \t\t\t `${A}${Join<Rest>}`\n// \t\t: ''\n// \t: ''\n\n// const template = <\n// \tconst T extends Readonly<(Template | Readonly<Template[]>)[]>\n// >(\n// \t...p: T\n// ): Join<T> => {\n// \treturn a as any\n// }\n\n// const create =\n// \t<const T extends string>(t: T): ((t: T) => void) =>\n// \t(t) =>\n// \t\tt\n\n// const optional = <\n// \tconst T extends Readonly<(Template | Readonly<Template[]>)[]>\n// >(\n// \t...p: T\n// ): T | undefined => {\n// \treturn undefined\n// }\n\n// template.optional = optional\n\n// const hi = create(\n// \ttemplate(\n// \t\t['seminar', 'millennium'],\n// \t\t':',\n// \t\t['Rio', 'Yuuka', 'Noa', 'Koyuki'],\n// \t\ttemplate.optional(template(',', ['Rio', 'Yuuka', 'Noa', 'Koyuki'])),\n// \t\ttemplate.optional(template(',', ['Rio', 'Yuuka', 'Noa', 'Koyuki'])),\n// \t\ttemplate.optional(template(',', ['Rio', 'Yuuka', 'Noa', 'Koyuki']))\n// \t)\n// )\n\n// hi(`seminar:Noa,Koyuki,Yuuka`)\n\n// const a = TypeCompiler.Compile(t.String())\n\n// console.log(v.Decode.toString())\n\n// const T = t.Transform(v.schema)\n// \t.Decode((value) => new Date(value)) // required: number to Date\n// \t.Encode((value) => value.getTime()) // required: Date to number\n\n// const decoded = Value.Decode(T, 0) // const decoded = Date(1970-01-01T00:00:00.000Z)\n// const encoded = Value.Encode(T, decoded)\n",
32
- "import type { Serve, Server, ServerWebSocket } from 'bun'\n\nimport { Memoirist } from 'memoirist'\nimport EventEmitter from 'eventemitter3'\nimport { type Static, type TSchema } from '@sinclair/typebox'\n\nimport { createTraceListener } from './trace'\nimport type { Context } from './context'\n\nimport { t, TypeCheck } from './type-system'\nimport { sucrose, sucroseTrace, type Sucrose } from './sucrose'\n\nimport { ElysiaWS, websocket } from './ws'\nimport type { WS } from './ws/types'\n\nimport {\n\tcloneInference,\n\tfnToContainer,\n\tlocalHookToLifeCycleStore,\n\tmergeDeep,\n\tPromiseGroup\n} from './utils'\nimport {\n\tcomposeHandler,\n\tcomposeGeneralHandler,\n\tcomposeErrorHandler,\n\tjitRoute\n} from './compose'\nimport {\n\tmergeHook,\n\tgetSchemaValidator,\n\tgetResponseSchemaValidator,\n\tchecksum,\n\tmergeLifeCycle,\n\tfilterGlobalHook,\n\tasHookType,\n\ttraceBackMacro,\n\treplaceUrlPath,\n\tisNumericString,\n\tcreateMacroManager,\n\tgetCookieValidator\n} from './utils'\n\nimport {\n\tcreateDynamicErrorHandler,\n\tcreateDynamicHandler,\n\ttype DynamicHandler\n} from './dynamic-handle'\n\nimport {\n\tERROR_CODE,\n\tisProduction,\n\tValidationError,\n\ttype ParseError,\n\ttype NotFoundError,\n\ttype InternalServerError\n} from './error'\n\nimport type {\n\tElysiaConfig,\n\tSingletonBase,\n\tDefinitionBase,\n\tHandler,\n\tComposedHandler,\n\tInputSchema,\n\tLocalHook,\n\tMergeSchema,\n\tRouteSchema,\n\tUnwrapRoute,\n\tInternalRoute,\n\tHTTPMethod,\n\tSchemaValidator,\n\tVoidHandler,\n\tPreHandler,\n\tBodyHandler,\n\tOptionalHandler,\n\tAfterHandler,\n\tErrorHandler,\n\tLifeCycleStore,\n\tMaybePromise,\n\tPrettify,\n\tPrettify2,\n\tListenCallback,\n\tAddPrefix,\n\tAddSuffix,\n\tAddPrefixCapitalize,\n\tAddSuffixCapitalize,\n\tTraceReporter,\n\tTraceHandler,\n\tMaybeArray,\n\tGracefulHandler,\n\tGetPathParameter,\n\tMapResponse,\n\tChecksum,\n\tMacroManager,\n\tBaseMacro,\n\tMacroToProperty,\n\tTransformHandler,\n\tMetadataBase,\n\tRouteBase,\n\tCreateEden,\n\tComposeElysiaResponse,\n\tInlineHandler,\n\tHookContainer,\n\tLifeCycleType,\n\tMacroQueue,\n\tEphemeralType,\n\tExcludeElysiaResponse\n} from './types'\nimport { isNotEmpty } from './handler'\n\ntype AnyElysia = Elysia<any, any, any, any, any, any, any, any>\n\n/**\n * ### Elysia Server\n * Main instance to create web server using Elysia\n *\n * ---\n * @example\n * ```typescript\n * import { Elysia } from 'elysia'\n *\n * new Elysia()\n * .get(\"/\", () => \"Hello\")\n * .listen(3000)\n * ```\n */\nexport default class Elysia<\n\tconst in out BasePath extends string = '',\n\tconst in out Scoped extends boolean = false,\n\tconst in out Singleton extends SingletonBase = {\n\t\tdecorator: {}\n\t\tstore: {}\n\t\tderive: {}\n\t\tresolve: {}\n\t},\n\tconst in out Definitions extends DefinitionBase = {\n\t\ttype: {}\n\t\terror: {}\n\t},\n\tconst in out Metadata extends MetadataBase = {\n\t\tschema: {}\n\t\tmacro: {}\n\t},\n\tconst out Routes extends RouteBase = {},\n\t// ? scoped\n\tconst in out Ephemeral extends EphemeralType = {\n\t\tderive: {}\n\t\tresolve: {}\n\t\tschema: {}\n\t},\n\t// ? local\n\tconst in out Volatile extends EphemeralType = {\n\t\tderive: {}\n\t\tresolve: {}\n\t\tschema: {}\n\t}\n> {\n\tconfig: ElysiaConfig<BasePath, Scoped>\n\n\tserver: Server | null = null\n\tprivate dependencies: Record<string, Checksum[]> = {}\n\tprivate reporter: TraceReporter = new EventEmitter()\n\n\t_routes: Routes = {} as any\n\n\t_types = {\n\t\tPrefix: '' as BasePath,\n\t\tScoped: false as Scoped,\n\t\tSingleton: {} as Singleton,\n\t\tDefinitions: {} as Definitions,\n\t\tMetadata: {} as Metadata\n\t}\n\n\t_ephemeral = {} as Ephemeral\n\t_volatile = {} as Volatile\n\n\tprotected singleton = {\n\t\tdecorator: {},\n\t\tstore: {},\n\t\tderive: {},\n\t\tresolve: {}\n\t} as Singleton\n\n\tget store(): Singleton['store'] {\n\t\treturn this.singleton.store\n\t}\n\n\tget decorator(): Singleton['decorator'] {\n\t\treturn this.singleton.decorator\n\t}\n\n\tget _scoped() {\n\t\treturn this.config.scoped as Scoped\n\t}\n\n\tprotected definitions = {\n\t\ttype: {} as Record<string, TSchema>,\n\t\terror: {} as Record<string, Error>\n\t}\n\n\tprotected extender = {\n\t\tmacros: <MacroQueue[]>[]\n\t}\n\n\tprotected validator: SchemaValidator | null = null\n\n\tevent: LifeCycleStore = {\n\t\tstart: [],\n\t\trequest: [],\n\t\tparse: [],\n\t\ttransform: [],\n\t\tbeforeHandle: [],\n\t\tafterHandle: [],\n\t\tmapResponse: [],\n\t\tonResponse: [],\n\t\ttrace: [],\n\t\terror: [],\n\t\tstop: []\n\t}\n\n\ttelemetry = {\n\t\tstack: undefined as string | undefined\n\t}\n\n\trouter = {\n\t\thttp: new Memoirist<ComposedHandler>(),\n\t\tws: new Memoirist<ComposedHandler>(),\n\t\t// Use in non-AOT mode\n\t\tdynamic: new Memoirist<DynamicHandler>(),\n\t\tstatic: {\n\t\t\thttp: {\n\t\t\t\thandlers: [] as ComposedHandler[],\n\t\t\t\tvariables: '',\n\t\t\t\tmap: {} as Record<\n\t\t\t\t\tstring,\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: string\n\t\t\t\t\t\tall?: string\n\t\t\t\t\t}\n\t\t\t\t>,\n\t\t\t\tall: ''\n\t\t\t},\n\t\t\t// Static WS Router is consists of pathname and websocket handler index to compose\n\t\t\tws: {} as Record<string, number>\n\t\t},\n\t\thistory: [] as InternalRoute[]\n\t}\n\n\tprotected inference: {\n\t\tevent: Sucrose.Inference\n\t\ttrace: Sucrose.TraceInference\n\t} = {\n\t\tevent: {\n\t\t\tbody: false,\n\t\t\tcookie: false,\n\t\t\theaders: false,\n\t\t\tqueries: [],\n\t\t\tquery: false,\n\t\t\tset: false,\n\t\t\tunknownQueries: false\n\t\t},\n\t\ttrace: {\n\t\t\trequest: false,\n\t\t\tparse: false,\n\t\t\ttransform: false,\n\t\t\thandle: false,\n\t\t\tbeforeHandle: false,\n\t\t\tafterHandle: false,\n\t\t\terror: false,\n\t\t\tcontext: false,\n\t\t\tstore: false,\n\t\t\tset: false\n\t\t}\n\t}\n\n\tprivate promisedModules = new PromiseGroup()\n\n\tconstructor(config?: ElysiaConfig<BasePath, Scoped>) {\n\t\tif (config?.tags) {\n\t\t\tif (!config.detail)\n\t\t\t\tconfig.detail = {\n\t\t\t\t\ttags: config.tags\n\t\t\t\t}\n\t\t\telse config.detail.tags = config.tags\n\t\t}\n\n\t\tthis.config = {\n\t\t\tforceErrorEncapsulation: true,\n\t\t\tprefix: '',\n\t\t\taot: true,\n\t\t\tstrictPath: false,\n\t\t\tglobal: false,\n\t\t\tcookie: {},\n\t\t\tanalytic: false,\n\t\t\t...config,\n\t\t\texperimental: config?.experimental ?? {},\n\t\t\tseed: config?.seed === undefined ? '' : config?.seed\n\t\t} as any\n\n\t\tif (config?.analytic && (config?.name || config?.seed !== undefined))\n\t\t\tthis.telemetry.stack = new Error().stack\n\t}\n\n\tprivate getServer() {\n\t\treturn this.server\n\t}\n\n\tget routes(): InternalRoute[] {\n\t\treturn this.router.history\n\t}\n\n\tprotected routeTree = new Map<string, number>()\n\n\tprivate applyMacro(\n\t\tlocalHook: LocalHook<any, any, any, any, any, any, any>\n\t) {\n\t\tif (this.extender.macros.length) {\n\t\t\tconst manage = createMacroManager({\n\t\t\t\tglobalHook: this.event,\n\t\t\t\tlocalHook\n\t\t\t})\n\n\t\t\tconst manager: MacroManager = {\n\t\t\t\tevents: {\n\t\t\t\t\tglobal: this.event,\n\t\t\t\t\tlocal: localHook\n\t\t\t\t},\n\t\t\t\tonParse: manage('parse') as any,\n\t\t\t\tonTransform: manage('transform') as any,\n\t\t\t\tonBeforeHandle: manage('beforeHandle') as any,\n\t\t\t\tonAfterHandle: manage('afterHandle') as any,\n\t\t\t\tonResponse: manage('onResponse') as any,\n\t\t\t\tmapResponse: manage('mapResponse') as any,\n\t\t\t\tonError: manage('error') as any\n\t\t\t}\n\n\t\t\tfor (const macro of this.extender.macros)\n\t\t\t\ttraceBackMacro(macro.fn(manager), localHook)\n\t\t}\n\t}\n\n\tprivate add(\n\t\tmethod: HTTPMethod,\n\t\tpath: string,\n\t\thandle: Handler<any, any, any> | any,\n\t\tlocalHook?: LocalHook<any, any, any, any, any, any>,\n\t\t{ allowMeta = false, skipPrefix = false } = {\n\t\t\tallowMeta: false as boolean | undefined,\n\t\t\tskipPrefix: false as boolean | undefined\n\t\t}\n\t) {\n\t\tlocalHook = localHookToLifeCycleStore(localHook)\n\n\t\tif (path !== '' && path.charCodeAt(0) !== 47) path = '/' + path\n\n\t\tif (this.config.prefix && !skipPrefix && !this.config.scoped)\n\t\t\tpath = this.config.prefix + path\n\n\t\tif (localHook?.type)\n\t\t\tswitch (localHook.type) {\n\t\t\t\tcase 'text':\n\t\t\t\t\tlocalHook.type = 'text/plain'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'json':\n\t\t\t\t\tlocalHook.type = 'application/json'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'formdata':\n\t\t\t\t\tlocalHook.type = 'multipart/form-data'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'urlencoded':\n\t\t\t\t\tlocalHook.type = 'application/x-www-form-urlencoded'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'arrayBuffer':\n\t\t\t\t\tlocalHook.type = 'application/octet-stream'\n\t\t\t\t\tbreak\n\n\t\t\t\tdefault:\n\t\t\t\t\tbreak\n\t\t\t}\n\n\t\tconst models = this.definitions.type\n\n\t\tlet _body: TypeCheck<any> | undefined,\n\t\t\t_headers: TypeCheck<any> | undefined,\n\t\t\t_params: TypeCheck<any> | undefined,\n\t\t\t_query: TypeCheck<any> | undefined,\n\t\t\t_cookie: TypeCheck<any> | undefined,\n\t\t\t_response:\n\t\t\t\t| TypeCheck<any>\n\t\t\t\t| Record<string, TypeCheck<any>>\n\t\t\t\t| undefined\n\n\t\t// ? Clone is need because of JIT, so the context doesn't switch between instance\n\t\tconst dynamic = !this.config.aot\n\n\t\tconst cloned = {\n\t\t\tbody: localHook?.body ?? (this.validator?.body as any),\n\t\t\theaders: localHook?.headers ?? (this.validator?.headers as any),\n\t\t\tparams: localHook?.params ?? (this.validator?.params as any),\n\t\t\tquery: localHook?.query ?? (this.validator?.query as any),\n\t\t\tcookie: localHook?.cookie ?? (this.validator?.cookie as any),\n\t\t\tresponse: localHook?.response ?? (this.validator?.response as any)\n\t\t}\n\n\t\tconst cookieValidator = () =>\n\t\t\tcloned.cookie\n\t\t\t\t? getCookieValidator({\n\t\t\t\t\t\tvalidator: cloned.cookie,\n\t\t\t\t\t\tdefaultConfig: this.config.cookie,\n\t\t\t\t\t\tconfig: cloned.cookie?.config ?? {},\n\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\tmodels\n\t\t\t\t })\n\t\t\t\t: undefined\n\n\t\tconst normalize = this.config.normalize\n\n\t\tconst validator =\n\t\t\tthis.config.precompile === true ||\n\t\t\t(typeof this.config.precompile === 'object' &&\n\t\t\t\tthis.config.precompile.schema === true)\n\t\t\t\t? {\n\t\t\t\t\t\tbody: getSchemaValidator(cloned.body, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t}),\n\t\t\t\t\t\theaders: getSchemaValidator(cloned.headers, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tadditionalProperties: true\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tparams: getSchemaValidator(cloned.params, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tquery: getSchemaValidator(cloned.query, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcookie: cookieValidator(),\n\t\t\t\t\t\tresponse: getResponseSchemaValidator(cloned.response, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t})\n\t\t\t\t }\n\t\t\t\t: ({\n\t\t\t\t\t\tget body() {\n\t\t\t\t\t\t\tif (_body) return _body\n\n\t\t\t\t\t\t\treturn (_body = getSchemaValidator(cloned.body, {\n\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget headers() {\n\t\t\t\t\t\t\tif (_headers) return _headers\n\n\t\t\t\t\t\t\treturn getSchemaValidator(cloned.headers, {\n\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\t\tadditionalProperties: true\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget params() {\n\t\t\t\t\t\t\tif (_params) return _params\n\n\t\t\t\t\t\t\treturn (_params = getSchemaValidator(\n\t\t\t\t\t\t\t\tcloned.params,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\t\tmodels\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t))\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget query() {\n\t\t\t\t\t\t\tif (_query) return _query\n\n\t\t\t\t\t\t\treturn (_query = getSchemaValidator(cloned.query, {\n\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\tmodels\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget cookie() {\n\t\t\t\t\t\t\tif (_cookie) return _cookie\n\n\t\t\t\t\t\t\treturn (_cookie = cookieValidator())\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget response() {\n\t\t\t\t\t\t\tif (_response) return _response\n\n\t\t\t\t\t\t\treturn (_response = getResponseSchemaValidator(\n\t\t\t\t\t\t\t\tcloned.response,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t))\n\t\t\t\t\t\t}\n\t\t\t\t } as any)\n\n\t\tconst loosePath = path.endsWith('/')\n\t\t\t? path.slice(0, path.length - 1)\n\t\t\t: path + '/'\n\n\t\t// ! Init default [] for hooks if undefined\n\t\tlocalHook = mergeHook(localHook, {}, { allowMacro: true })\n\n\t\tif (localHook.tags) {\n\t\t\tif (!localHook.detail)\n\t\t\t\tlocalHook.detail = {\n\t\t\t\t\ttags: localHook.tags\n\t\t\t\t}\n\t\t\telse localHook.detail.tags = localHook.tags\n\t\t}\n\n\t\tif (isNotEmpty(this.config.detail))\n\t\t\tlocalHook.detail = mergeDeep(\n\t\t\t\tObject.assign({}, this.config.detail!),\n\t\t\t\tlocalHook.detail\n\t\t\t)\n\n\t\tthis.applyMacro(localHook)\n\n\t\tconst hooks = mergeHook(this.event, localHook)\n\n\t\tif (this.config.aot === false) {\n\t\t\tthis.router.dynamic.add(method, path, {\n\t\t\t\tvalidator,\n\t\t\t\thooks,\n\t\t\t\tcontent: localHook?.type as string,\n\t\t\t\thandle\n\t\t\t})\n\n\t\t\tif (this.config.strictPath === false) {\n\t\t\t\tthis.router.dynamic.add(method, loosePath, {\n\t\t\t\t\tvalidator,\n\t\t\t\t\thooks,\n\t\t\t\t\tcontent: localHook?.type as string,\n\t\t\t\t\thandle\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tthis.router.history.push({\n\t\t\t\tmethod,\n\t\t\t\tpath,\n\t\t\t\tcomposed: null,\n\t\t\t\thandler: handle,\n\t\t\t\thooks: hooks as any\n\t\t\t})\n\n\t\t\treturn\n\t\t}\n\n\t\tlet composed:\n\t\t\t| ((context: Context<any, any, any>) => MaybePromise<Response>)\n\t\t\t| undefined = undefined\n\n\t\tconst shouldPrecompile =\n\t\t\tthis.config.precompile === true ||\n\t\t\t(typeof this.config.precompile === 'object' &&\n\t\t\t\tthis.config.precompile.compose === true)\n\n\t\tconst appInference = cloneInference(this.inference)\n\n\t\tconst mainHandler = shouldPrecompile\n\t\t\t? composeHandler({\n\t\t\t\t\tapp: this,\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod,\n\t\t\t\t\tlocalHook: mergeHook(localHook),\n\t\t\t\t\thooks,\n\t\t\t\t\tvalidator,\n\t\t\t\t\thandler: handle,\n\t\t\t\t\tallowMeta,\n\t\t\t\t\tappInference\n\t\t\t })\n\t\t\t: (((context: Context) => {\n\t\t\t\t\tif (composed) return composed(context)\n\n\t\t\t\t\treturn (composed = composeHandler({\n\t\t\t\t\t\tapp: this,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tlocalHook: mergeHook(localHook),\n\t\t\t\t\t\thooks,\n\t\t\t\t\t\tvalidator,\n\t\t\t\t\t\thandler: handle,\n\t\t\t\t\t\tallowMeta,\n\t\t\t\t\t\tappInference\n\t\t\t\t\t}) as any)(context)\n\t\t\t }) as ComposedHandler)\n\n\t\tif (!shouldPrecompile)\n\t\t\tmainHandler.compose = () => {\n\t\t\t\treturn (mainHandler.composed = composeHandler({\n\t\t\t\t\tapp: this,\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod,\n\t\t\t\t\tlocalHook: mergeHook(localHook),\n\t\t\t\t\thooks,\n\t\t\t\t\tvalidator,\n\t\t\t\t\thandler: handle,\n\t\t\t\t\tallowMeta,\n\t\t\t\t\tappInference\n\t\t\t\t}) as any)\n\t\t\t}\n\n\t\tlet routeIndex = this.router.history.length\n\n\t\tif (this.routeTree.has(method + path)) {\n\t\t\trouteIndex = this.router.history.findIndex(\n\t\t\t\t(route) => route.path === path && route.method === method\n\t\t\t)\n\n\t\t\tif (routeIndex !== -1) {\n\t\t\t\t// remove route previously defined\n\t\t\t\tconst removed = this.router.history.splice(routeIndex, 1)[0]\n\n\t\t\t\tif (\n\t\t\t\t\tremoved &&\n\t\t\t\t\tthis.routeTree.has(removed?.method + removed?.path)\n\t\t\t\t)\n\t\t\t\t\tthis.routeTree.delete(removed.method + removed.path)\n\t\t\t}\n\t\t}\n\n\t\tthis.routeTree.set(method + path, routeIndex)\n\t\tthis.router.history.push({\n\t\t\tmethod,\n\t\t\tpath,\n\t\t\tcomposed: mainHandler,\n\t\t\thandler: handle,\n\t\t\thooks: hooks as any\n\t\t})\n\n\t\tconst staticRouter = this.router.static.http\n\n\t\tif (method === '$INTERNALWS') {\n\t\t\tconst loose = this.config.strictPath\n\t\t\t\t? undefined\n\t\t\t\t: path.endsWith('/')\n\t\t\t\t? path.slice(0, path.length - 1)\n\t\t\t\t: path + '/'\n\n\t\t\tif (path.indexOf(':') === -1 && path.indexOf('*') === -1) {\n\t\t\t\tconst index = staticRouter.handlers.length\n\t\t\t\tstaticRouter.handlers.push(mainHandler)\n\n\t\t\t\tstaticRouter.variables += `const st${index} = staticRouter.handlers[${index}]\\n`\n\n\t\t\t\tthis.router.static.ws[path] = index\n\t\t\t\tif (loose) this.router.static.ws[loose] = index\n\t\t\t} else {\n\t\t\t\tthis.router.ws.add('ws', path, mainHandler)\n\t\t\t\tif (loose) this.router.ws.add('ws', loose, mainHandler)\n\t\t\t}\n\n\t\t\treturn\n\t\t}\n\n\t\tif (path.indexOf(':') === -1 && path.indexOf('*') === -1) {\n\t\t\tconst index = staticRouter.handlers.length\n\t\t\tstaticRouter.handlers.push(mainHandler)\n\n\t\t\tstaticRouter.variables += shouldPrecompile\n\t\t\t\t? `const st${index} = staticRouter.handlers[${index}]\\n`\n\t\t\t\t: `let st${index} = staticRouter.handlers[${index}]\\nlet stc${index}\\n`\n\n\t\t\tif (!staticRouter.map[path])\n\t\t\t\tstaticRouter.map[path] = {\n\t\t\t\t\tcode: ''\n\t\t\t\t}\n\n\t\t\tif (method === 'ALL')\n\t\t\t\tstaticRouter.map[path].all = shouldPrecompile\n\t\t\t\t\t? `default: return st${index}(ctx)\\n`\n\t\t\t\t\t: `default: ${jitRoute(index)}\\n`\n\t\t\telse\n\t\t\t\tstaticRouter.map[path].code = shouldPrecompile\n\t\t\t\t\t? `case '${method}': return st${index}(ctx)\\n${staticRouter.map[path].code}`\n\t\t\t\t\t: `case '${method}': ${jitRoute(index)}\\n${\n\t\t\t\t\t\t\tstaticRouter.map[path].code\n\t\t\t\t\t }`\n\n\t\t\tif (!this.config.strictPath) {\n\t\t\t\tif (!staticRouter.map[loosePath])\n\t\t\t\t\tstaticRouter.map[loosePath] = {\n\t\t\t\t\t\tcode: ''\n\t\t\t\t\t}\n\n\t\t\t\tif (method === 'ALL')\n\t\t\t\t\tstaticRouter.map[loosePath].all = shouldPrecompile\n\t\t\t\t\t\t? `default: return st${index}(ctx)\\n`\n\t\t\t\t\t\t: `default: ${jitRoute(index)}\\n`\n\t\t\t\telse\n\t\t\t\t\tstaticRouter.map[loosePath].code = shouldPrecompile\n\t\t\t\t\t\t? `case '${method}': return st${index}(ctx)\\n${staticRouter.map[loosePath].code}`\n\t\t\t\t\t\t: `case '${method}': ${jitRoute(index)}\\n${\n\t\t\t\t\t\t\t\tstaticRouter.map[loosePath].code\n\t\t\t\t\t\t }`\n\t\t\t}\n\t\t} else {\n\t\t\tthis.router.http.add(method, path, mainHandler)\n\n\t\t\tif (!this.config.strictPath)\n\t\t\t\tthis.router.http.add(\n\t\t\t\t\tmethod,\n\t\t\t\t\tpath.endsWith('/')\n\t\t\t\t\t\t? path.slice(0, path.length - 1)\n\t\t\t\t\t\t: path + '/',\n\t\t\t\t\tmainHandler\n\t\t\t\t)\n\t\t}\n\t}\n\n\tprivate setHeaders?: Context['set']['headers']\n\theaders(header: Context['set']['headers'] | undefined) {\n\t\tif (!header) return this\n\n\t\tif (!this.setHeaders) this.setHeaders = {}\n\n\t\tthis.setHeaders = mergeDeep(this.setHeaders, header)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### start | Life cycle event\n\t * Called after server is ready for serving\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onStart(({ url, port }) => {\n\t * console.log(\"Running at ${url}:${port}\")\n\t * })\n\t * .listen(3000)\n\t * ```\n\t */\n\tonStart(handler: MaybeArray<GracefulHandler<this>>) {\n\t\tthis.on('start', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### request | Life cycle event\n\t * Called on every new request is accepted\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onRequest(({ method, url }) => {\n\t * saveToAnalytic({ method, url })\n\t * })\n\t * ```\n\t */\n\tonRequest<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tPreHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t) {\n\t\tthis.on('request', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### parse | Life cycle event\n\t * Callback function to handle body parsing\n\t *\n\t * If truthy value is returned, will be assigned to `context.body`\n\t * Otherwise will skip the callback and look for the next one.\n\t *\n\t * Equivalent to Express's body parser\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onParse((request, contentType) => {\n\t * if(contentType === \"application/json\")\n\t * return request.json()\n\t * })\n\t * ```\n\t */\n\tonParse<const Schema extends RouteSchema>(\n\t\tparser: MaybeArray<\n\t\t\tBodyHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### parse | Life cycle event\n\t * Callback function to handle body parsing\n\t *\n\t * If truthy value is returned, will be assigned to `context.body`\n\t * Otherwise will skip the callback and look for the next one.\n\t *\n\t * Equivalent to Express's body parser\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onParse((request, contentType) => {\n\t * if(contentType === \"application/json\")\n\t * return request.json()\n\t * })\n\t * ```\n\t */\n\tonParse<const Schema extends RouteSchema, const Type extends LifeCycleType>(\n\t\toptions: { as?: Type },\n\t\tparser: MaybeArray<\n\t\t\tBodyHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonParse(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('parse', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'parse',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### transform | Life cycle event\n\t * Assign or transform anything related to context before validation.\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onTransform(({ params }) => {\n\t * if(params.id)\n\t * params.id = +params.id\n\t * })\n\t * ```\n\t */\n\tonTransform<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tTransformHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### transform | Life cycle event\n\t * Assign or transform anything related to context before validation.\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onTransform(({ params }) => {\n\t * if(params.id)\n\t * params.id = +params.id\n\t * })\n\t * ```\n\t */\n\tonTransform<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tTransformHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonTransform(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('transform', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'transform',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tresolve<\n\t\tconst Resolver extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\tresolver: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton &\n\t\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['derive']\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t })\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Resolver>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tSingleton['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t\t\t>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tresolve<const Resolver extends Record<string, unknown>>(\n\t\tresolver: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton & {\n\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t},\n\t\t\t\t\tBasePath\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Resolver>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Volatile['resolve']\n\t\t\tresolve: Prettify<\n\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t>\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\tresolve(\n\t\toptionsOrResolve: { as?: LifeCycleType } | Function,\n\t\tresolve?: Function\n\t) {\n\t\tif (!resolve) {\n\t\t\tresolve = optionsOrResolve as any\n\t\t\toptionsOrResolve = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'resolve',\n\t\t\tfn: resolve!\n\t\t}\n\n\t\treturn this.onBeforeHandle(optionsOrResolve as any, hook as any) as any\n\t}\n\n\tmapResolve<const NewResolver extends Record<string, unknown>>(\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t) => MaybePromise<NewResolver>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Volatile['derive']\n\t\t\tresolve: NewResolver\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\tmapResolve<\n\t\tconst NewResolver extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t) => MaybePromise<NewResolver>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Awaited<NewResolver>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewResolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<NewResolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\tmapResolve(\n\t\toptionsOrResolve: Function | { as?: LifeCycleType },\n\t\tmapper?: Function\n\t) {\n\t\tif (!mapper) {\n\t\t\tmapper = optionsOrResolve as any\n\t\t\toptionsOrResolve = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'resolve',\n\t\t\tfn: mapper!\n\t\t}\n\n\t\treturn this.onBeforeHandle(optionsOrResolve as any, hook as any) as any\n\t}\n\n\t/**\n\t * ### Before Handle | Life cycle event\n\t * Execute after validation and before the main route handler.\n\t *\n\t * If truthy value is returned, will be assigned as `Response` and skip the main handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onBeforeHandle(({ params: { id }, status }) => {\n\t * if(id && !isExisted(id)) {\n\t * \t status(401)\n\t *\n\t * return \"Unauthorized\"\n\t * \t }\n\t * })\n\t * ```\n\t */\n\tonBeforeHandle<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tOptionalHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### Before Handle | Life cycle event\n\t * Execute after validation and before the main route handler.\n\t *\n\t * If truthy value is returned, will be assigned as `Response` and skip the main handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onBeforeHandle(({ params: { id }, status }) => {\n\t * if(id && !isExisted(id)) {\n\t * \t status(401)\n\t *\n\t * return \"Unauthorized\"\n\t * \t }\n\t * })\n\t * ```\n\t */\n\tonBeforeHandle<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tOptionalHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t }),\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\tonBeforeHandle(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('beforeHandle', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'beforeHandle',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tonAfterHandle<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tAfterHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tonAfterHandle<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: LifeCycleType },\n\t\thandler: MaybeArray<\n\t\t\tAfterHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonAfterHandle(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('afterHandle', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'afterHandle',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .mapResponse((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tmapResponse<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tMapResponse<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .mapResponse((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tmapResponse<const Schema extends RouteSchema, Type extends LifeCycleType>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tMapResponse<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tmapResponse(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('mapResponse', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'mapResponse',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### response | Life cycle event\n\t * Called when handler is executed\n\t * Good for analytic metrics\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\n\tonResponse<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tVoidHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### response | Life cycle event\n\t * Called when handler is executed\n\t * Good for analytic metrics\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\n\tonResponse<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tVoidHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonResponse(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('response', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'response',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\ttrace<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<TraceHandler<Schema, Singleton>>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\ttrace<const Schema extends RouteSchema>(\n\t\toptions: { as?: LifeCycleType },\n\t\thandler: MaybeArray<TraceHandler<Schema, Singleton>>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\ttrace(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) {\n\t\t\thandler = options as MaybeArray<Function>\n\t\t\toptions = { as: 'local' }\n\t\t}\n\n\t\tif (!Array.isArray(handler)) handler = [handler] as Function[]\n\n\t\tfor (const fn of handler)\n\t\t\tthis.reporter.on(\n\t\t\t\t'event',\n\t\t\t\tcreateTraceListener(\n\t\t\t\t\t() => this.reporter,\n\t\t\t\t\tthis.event.trace.length,\n\t\t\t\t\tfn as any\n\t\t\t\t)\n\t\t\t)\n\n\t\tthis.on(options as { as?: LifeCycleType }, 'trace', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * Register errors\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * class CustomError extends Error {\n\t * constructor() {\n\t * super()\n\t * }\n\t * }\n\t *\n\t * new Elysia()\n\t * .error('CUSTOM_ERROR', CustomError)\n\t * ```\n\t */\n\terror<\n\t\tconst Errors extends Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tprototype: Error\n\t\t\t}\n\t\t>\n\t>(\n\t\terrors: Errors\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Definitions['type']\n\t\t\terror: Definitions['error'] & {\n\t\t\t\t[K in keyof Errors]: Errors[K] extends {\n\t\t\t\t\tprototype: infer LiteralError extends Error\n\t\t\t\t}\n\t\t\t\t\t? LiteralError\n\t\t\t\t\t: Errors[K]\n\t\t\t}\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * Register errors\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * class CustomError extends Error {\n\t * constructor() {\n\t * super()\n\t * }\n\t * }\n\t *\n\t * new Elysia()\n\t * .error({\n\t * CUSTOM_ERROR: CustomError\n\t * })\n\t * ```\n\t */\n\terror<\n\t\tName extends string,\n\t\tconst CustomError extends {\n\t\t\tprototype: Error\n\t\t}\n\t>(\n\t\tname: Name,\n\t\terrors: CustomError\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Definitions['type']\n\t\t\terror: Definitions['error'] & {\n\t\t\t\t[name in Name]: CustomError extends {\n\t\t\t\t\tprototype: infer LiteralError extends Error\n\t\t\t\t}\n\t\t\t\t\t? LiteralError\n\t\t\t\t\t: CustomError\n\t\t\t}\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * Register errors\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * class CustomError extends Error {\n\t * constructor() {\n\t * super()\n\t * }\n\t * }\n\t *\n\t * new Elysia()\n\t * .error('CUSTOM_ERROR', CustomError)\n\t * ```\n\t */\n\terror<const NewErrors extends Record<string, Error>>(\n\t\tmapper: (decorators: Definitions['error']) => NewErrors\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Definitions['type']\n\t\t\terror: {\n\t\t\t\t[K in keyof NewErrors]: NewErrors[K] extends {\n\t\t\t\t\tprototype: infer LiteralError extends Error\n\t\t\t\t}\n\t\t\t\t\t? LiteralError\n\t\t\t\t\t: never\n\t\t\t}\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\terror(\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tname:\n\t\t\t| string\n\t\t\t| Record<\n\t\t\t\t\tstring,\n\t\t\t\t\t{\n\t\t\t\t\t\tprototype: Error\n\t\t\t\t\t}\n\t\t\t >\n\t\t\t| Function,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\terror?: {\n\t\t\tprototype: Error\n\t\t}\n\t): AnyElysia {\n\t\tswitch (typeof name) {\n\t\t\tcase 'string':\n\t\t\t\t// @ts-ignore\n\t\t\t\terror.prototype[ERROR_CODE] = name\n\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.definitions.error[name] = error\n\n\t\t\t\treturn this\n\n\t\t\tcase 'function':\n\t\t\t\tthis.definitions.error = name(this.definitions.error)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\tfor (const [code, error] of Object.entries(name)) {\n\t\t\t// @ts-ignore\n\t\t\terror.prototype[ERROR_CODE] = code as any\n\n\t\t\tthis.definitions.error[code] = error as any\n\t\t}\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### Error | Life cycle event\n\t * Called when error is thrown during processing request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\tonError<const Schema extends RouteSchema>(\n\t\thandler: ErrorHandler<\n\t\t\tDefinitions['error'],\n\t\t\tMergeSchema<\n\t\t\t\tSchema,\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t\t>,\n\t\t\tSingleton\n\t\t>\n\t): this\n\n\t/**\n\t * ### Error | Life cycle event\n\t * Called when error is thrown during processing request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\tonError<const Schema extends RouteSchema>(\n\t\toptions: { as?: LifeCycleType },\n\t\thandler: ErrorHandler<\n\t\t\tDefinitions['error'],\n\t\t\tMergeSchema<\n\t\t\t\tSchema,\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t\t>,\n\t\t\tSingleton\n\t\t>\n\t): this\n\n\t/**\n\t * ### Error | Life cycle event\n\t * Called when error is thrown during processing request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\tonError(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('error', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'error',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### stop | Life cycle event\n\t * Called after server stop serving request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onStop((app) => {\n\t * cleanup()\n\t * })\n\t * ```\n\t */\n\tonStop(handler: MaybeArray<GracefulHandler<this>>) {\n\t\tthis.on('stop', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### on\n\t * Syntax sugar for attaching life cycle event by name\n\t *\n\t * Does the exact same thing as `.on[Event]()`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .on('error', ({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\ton<Event extends keyof LifeCycleStore>(\n\t\ttype: Exclude<Event, 'onResponse'> | 'response',\n\t\thandlers: MaybeArray<\n\t\t\tExtract<LifeCycleStore[Event], HookContainer[]>[0]['fn']\n\t\t>\n\t): this\n\n\t/**\n\t * ### on\n\t * Syntax sugar for attaching life cycle event by name\n\t *\n\t * Does the exact same thing as `.on[Event]()`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .on('error', ({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\ton<const Event extends keyof LifeCycleStore>(\n\t\toptions: { as?: LifeCycleType },\n\t\ttype: Exclude<Event, 'onResponse'> | 'response',\n\t\thandlers: MaybeArray<Extract<LifeCycleStore[Event], Function[]>[0]>\n\t): this\n\n\ton(\n\t\toptionsOrType: { as?: LifeCycleType } | string,\n\t\ttypeOrHandlers: MaybeArray<Function | HookContainer> | string,\n\t\thandlers?: MaybeArray<Function | HookContainer>\n\t) {\n\t\tlet type: Exclude<keyof LifeCycleStore, 'onResponse'> | 'onResponse'\n\n\t\tswitch (typeof optionsOrType) {\n\t\t\tcase 'string':\n\t\t\t\ttype = optionsOrType as any\n\t\t\t\thandlers = typeOrHandlers as any\n\n\t\t\t\tbreak\n\n\t\t\tcase 'object':\n\t\t\t\ttype = typeOrHandlers as any\n\t\t\t\tbreak\n\t\t}\n\n\t\t// @ts-expect-error possible user error, leave it on\n\t\tif (type === 'response') type = 'onResponse'\n\n\t\tif (Array.isArray(handlers)) handlers = fnToContainer(handlers)\n\t\telse {\n\t\t\tif (typeof handlers === 'function')\n\t\t\t\thandlers = [\n\t\t\t\t\t{\n\t\t\t\t\t\tfn: handlers\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\telse handlers = [handlers!]\n\t\t}\n\n\t\tconst handles = handlers as HookContainer[]\n\n\t\tfor (const handle of handles)\n\t\t\thandle.scope =\n\t\t\t\ttypeof optionsOrType === 'string'\n\t\t\t\t\t? 'local'\n\t\t\t\t\t: optionsOrType?.as ?? 'local'\n\n\t\tif (type === 'trace')\n\t\t\tsucroseTrace(\n\t\t\t\thandles.map((x) => x.fn) as TraceHandler[],\n\t\t\t\tthis.inference.trace\n\t\t\t)\n\t\telse\n\t\t\tsucrose(\n\t\t\t\t{\n\t\t\t\t\t[type]: handles.map((x) => x.fn)\n\t\t\t\t},\n\t\t\t\tthis.inference.event\n\t\t\t)\n\n\t\tfor (const handle of handles) {\n\t\t\tconst fn = asHookType(handle, 'global', { skipIfHasType: true })\n\n\t\t\tswitch (type) {\n\t\t\t\tcase 'start':\n\t\t\t\t\tthis.event.start.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'request':\n\t\t\t\t\tthis.event.request.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'parse':\n\t\t\t\t\tthis.event.parse.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'transform':\n\t\t\t\t\tthis.event.transform.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'beforeHandle':\n\t\t\t\t\tthis.event.beforeHandle.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'afterHandle':\n\t\t\t\t\tthis.event.afterHandle.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'mapResponse':\n\t\t\t\t\tthis.event.mapResponse.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'onResponse':\n\t\t\t\t\tthis.event.onResponse.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'trace':\n\t\t\t\t\tthis.event.trace.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'error':\n\t\t\t\t\tthis.event.error.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'stop':\n\t\t\t\t\tthis.event.stop.push(fn as any)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn this\n\t}\n\n\tpropagate(): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tPrettify2<Ephemeral & Volatile>,\n\t\t{\n\t\t\tderive: {}\n\t\t\tresolve: {}\n\t\t\tschema: {}\n\t\t}\n\t> {\n\t\t/**\n\t\t * Since it's a plugin, which means that ephemeral is demoted to volatile.\n\t\t * Which means there's no volatile and all previous ephemeral become volatile\n\t\t * We can just promote back without worry\n\t\t */\n\t\tconst promoteEvent = (events: (HookContainer | Function)[]) => {\n\t\t\tfor (const event of events) {\n\t\t\t\tif ('scope' in event && event.scope === 'local')\n\t\t\t\t\tevent.scope = 'scoped'\n\t\t\t}\n\t\t}\n\n\t\tpromoteEvent(this.event.parse)\n\t\tpromoteEvent(this.event.transform)\n\t\tpromoteEvent(this.event.beforeHandle)\n\t\tpromoteEvent(this.event.afterHandle)\n\t\tpromoteEvent(this.event.mapResponse)\n\t\tpromoteEvent(this.event.onResponse)\n\t\tpromoteEvent(this.event.trace)\n\t\tpromoteEvent(this.event.error)\n\n\t\treturn this as any\n\t}\n\n\tgroup<\n\t\tconst Prefix extends string,\n\t\tconst NewElysia extends Elysia<any, any, any, any, any, any, any, any>\n\t>(\n\t\tprefix: Prefix,\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\t`${BasePath}${Prefix}`,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tPrettify<Routes & NewElysia['_routes']>,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tgroup<\n\t\tconst Prefix extends string,\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Input extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<Input, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\tprefix: Prefix,\n\t\tschema: LocalHook<\n\t\t\tInput,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Prefix}`\n\t\t>,\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\t`${BasePath}${Prefix}`,\n\t\t\t\tfalse,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\t{\n\t\t\t\t\tschema: Schema\n\t\t\t\t\tmacro: Metadata['macro']\n\t\t\t\t},\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes & NewElysia['_routes'],\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### group\n\t * Encapsulate and group path with prefix\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .group('/v1', app => app\n\t * .get('/', () => 'Hi')\n\t * .get('/name', () => 'Elysia')\n\t * })\n\t * ```\n\t */\n\tgroup(\n\t\tprefix: string,\n\t\tschemaOrRun:\n\t\t\t| LocalHook<any, any, any, any, any, any>\n\t\t\t| ((group: AnyElysia) => AnyElysia),\n\t\trun?: (group: AnyElysia) => AnyElysia\n\t): AnyElysia {\n\t\tconst instance = new Elysia({\n\t\t\t...this.config,\n\t\t\tprefix: ''\n\t\t})\n\n\t\tinstance.singleton = { ...this.singleton }\n\t\tinstance.definitions = { ...this.definitions }\n\t\tinstance.getServer = () => this.server\n\t\tinstance.inference = cloneInference(this.inference)\n\n\t\tconst isSchema = typeof schemaOrRun === 'object'\n\t\tconst sandbox = (isSchema ? run! : schemaOrRun)(instance)\n\t\tthis.singleton = mergeDeep(this.singleton, instance.singleton) as any\n\t\tthis.definitions = mergeDeep(this.definitions, instance.definitions)\n\n\t\tif (sandbox.event.request.length)\n\t\t\tthis.event.request = [\n\t\t\t\t...(this.event.request || []),\n\t\t\t\t...((sandbox.event.request || []) as any)\n\t\t\t]\n\n\t\tif (sandbox.event.onResponse.length)\n\t\t\tthis.event.onResponse = [\n\t\t\t\t...(this.event.onResponse || []),\n\t\t\t\t...((sandbox.event.onResponse || []) as any)\n\t\t\t]\n\n\t\tthis.model(sandbox.definitions.type)\n\n\t\tObject.values(instance.router.history).forEach(\n\t\t\t({ method, path, handler, hooks }) => {\n\t\t\t\tpath = (isSchema ? '' : this.config.prefix) + prefix + path\n\n\t\t\t\tif (isSchema) {\n\t\t\t\t\tconst hook = schemaOrRun\n\t\t\t\t\tconst localHook = hooks as LocalHook<\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany\n\t\t\t\t\t>\n\n\t\t\t\t\tthis.add(\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\thandler,\n\t\t\t\t\t\tmergeHook(hook, {\n\t\t\t\t\t\t\t...(localHook || {}),\n\t\t\t\t\t\t\terror: !localHook.error\n\t\t\t\t\t\t\t\t? sandbox.event.error\n\t\t\t\t\t\t\t\t: Array.isArray(localHook.error)\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t...(localHook.error || {}),\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || {})\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\tlocalHook.error,\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || {})\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tthis.add(\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\thandler,\n\t\t\t\t\t\tmergeHook(\n\t\t\t\t\t\t\thooks as LocalHook<any, any, any, any, any, any>,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\terror: sandbox.event.error\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tskipPrefix: true\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t)\n\n\t\treturn this as any\n\t}\n\n\tguard<\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\thook: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\tBasePath\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Volatile['resolve']\n\t\t\tresolve: Volatile['resolve']\n\t\t\tschema: MergeSchema<\n\t\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t\t>\n\t\t}\n\t>\n\n\tguard<\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\t{\n\t\t\t\t\tschema: Prettify<Schema>\n\t\t\t\t\tmacro: Metadata['macro']\n\t\t\t\t},\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tPrettify<Routes & NewElysia['_routes']>,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tguard<\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\tschema: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t''\n\t\t>,\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\t{\n\t\t\t\t\tschema: Prettify<Schema>\n\t\t\t\t\tmacro: Metadata['macro']\n\t\t\t\t},\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tPrettify<Routes & NewElysia['_routes']>,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### guard\n\t * Encapsulate and pass hook into all child handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .guard({\n\t * schema: {\n\t * body: t.Object({\n\t * username: t.String(),\n\t * password: t.String()\n\t * })\n\t * }\n\t * }, app => app\n\t * .get(\"/\", () => 'Hi')\n\t * .get(\"/name\", () => 'Elysia')\n\t * })\n\t * ```\n\t */\n\tguard(\n\t\thook:\n\t\t\t| LocalHook<any, any, any, any, any, any, any>\n\t\t\t| ((group: AnyElysia) => AnyElysia),\n\t\trun?: (group: AnyElysia) => AnyElysia\n\t): AnyElysia {\n\t\tif (!run) {\n\t\t\tif (typeof hook === 'object') {\n\t\t\t\tthis.applyMacro(hook)\n\t\t\t\tthis.event = mergeLifeCycle(this.event, hook)\n\t\t\t\tthis.validator = {\n\t\t\t\t\tbody: hook.body ?? this.validator?.body,\n\t\t\t\t\theaders: hook.headers ?? this.validator?.headers,\n\t\t\t\t\tparams: hook.params ?? this.validator?.params,\n\t\t\t\t\tquery: hook.query ?? this.validator?.query,\n\t\t\t\t\tresponse: hook.response ?? this.validator?.response,\n\t\t\t\t\tcookie: hook.cookie ?? this.validator?.cookie\n\t\t\t\t}\n\n\t\t\t\tif (hook.detail) {\n\t\t\t\t\tif (this.config.detail)\n\t\t\t\t\t\tthis.config.detail = mergeDeep(\n\t\t\t\t\t\t\tObject.assign({}, this.config.detail),\n\t\t\t\t\t\t\thook.detail\n\t\t\t\t\t\t)\n\t\t\t\t\telse this.config.detail = hook.detail\n\t\t\t\t}\n\n\t\t\t\tif (hook?.tags) {\n\t\t\t\t\tif (!this.config.detail)\n\t\t\t\t\t\tthis.config.detail = {\n\t\t\t\t\t\t\ttags: hook.tags\n\t\t\t\t\t\t}\n\t\t\t\t\telse this.config.detail.tags = hook.tags\n\t\t\t\t}\n\n\t\t\t\treturn this\n\t\t\t}\n\n\t\t\treturn this.guard({}, hook)\n\t\t}\n\n\t\tconst instance = new Elysia({\n\t\t\t...this.config,\n\t\t\tprefix: ''\n\t\t})\n\t\tinstance.singleton = { ...this.singleton }\n\t\tinstance.definitions = { ...this.definitions }\n\t\tinstance.inference = cloneInference(this.inference)\n\n\t\tconst sandbox = run(instance)\n\t\tthis.singleton = mergeDeep(this.singleton, instance.singleton) as any\n\t\tthis.definitions = mergeDeep(this.definitions, instance.definitions)\n\n\t\t// ? Inject getServer for websocket and trace (important, do not remove)\n\t\tsandbox.getServer = () => this.server\n\n\t\tif (sandbox.event.request.length)\n\t\t\tthis.event.request = [\n\t\t\t\t...(this.event.request || []),\n\t\t\t\t...(sandbox.event.request || [])\n\t\t\t]\n\n\t\tif (sandbox.event.onResponse.length)\n\t\t\tthis.event.onResponse = [\n\t\t\t\t...(this.event.onResponse || []),\n\t\t\t\t...(sandbox.event.onResponse || [])\n\t\t\t]\n\n\t\tthis.model(sandbox.definitions.type)\n\n\t\tObject.values(instance.router.history).forEach(\n\t\t\t({ method, path, handler, hooks: localHook }) => {\n\t\t\t\tthis.add(\n\t\t\t\t\tmethod,\n\t\t\t\t\tpath,\n\t\t\t\t\thandler,\n\t\t\t\t\tmergeHook(\n\t\t\t\t\t\thook as LocalHook<any, any, any, any, any>,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...((localHook || {}) as LocalHook<\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany\n\t\t\t\t\t\t\t>),\n\t\t\t\t\t\t\terror: !localHook.error\n\t\t\t\t\t\t\t\t? sandbox.event.error\n\t\t\t\t\t\t\t\t: Array.isArray(localHook.error)\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t...(localHook.error || {}),\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || [])\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\tlocalHook.error,\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || [])\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tallowMacro: true\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * Inline fn\n\t */\n\tuse<\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Param extends AnyElysia = this\n\t>(\n\t\tplugin: MaybePromise<(app: Param) => MaybePromise<NewElysia>>\n\t): NewElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & NewElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<Definitions & NewElysia['_types']['Definitions']>,\n\t\t\t\tPrettify2<Metadata & NewElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tPrettify2<Ephemeral & NewElysia['_ephemeral']>,\n\t\t\t\tPrettify2<Volatile & NewElysia['_volatile']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\n\t/**\n\t * Entire Instance\n\t **/\n\tuse<const NewElysia extends AnyElysia>(\n\t\tinstance: MaybePromise<NewElysia>\n\t): NewElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & NewElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<Definitions & NewElysia['_types']['Definitions']>,\n\t\t\t\tPrettify2<Metadata & NewElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tPrettify2<Volatile & NewElysia['_ephemeral']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\n\t/**\n\t * Import fn\n\t */\n\tuse<const NewElysia extends AnyElysia>(\n\t\tplugin: Promise<{\n\t\t\tdefault: (elysia: AnyElysia) => MaybePromise<NewElysia>\n\t\t}>\n\t): NewElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & NewElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<Definitions & NewElysia['_types']['Definitions']>,\n\t\t\t\tPrettify2<Metadata & NewElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tPrettify2<Ephemeral & NewElysia['_ephemeral']>,\n\t\t\t\tPrettify2<Volatile & NewElysia['_volatile']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\n\t/**\n\t * Import entire instance\n\t */\n\tuse<const LazyLoadElysia extends AnyElysia>(\n\t\tplugin: Promise<{\n\t\t\tdefault: LazyLoadElysia\n\t\t}>\n\t): LazyLoadElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & LazyLoadElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<\n\t\t\t\t\tDefinitions & LazyLoadElysia['_types']['Definitions']\n\t\t\t\t>,\n\t\t\t\tPrettify2<Metadata & LazyLoadElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & LazyLoadElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, LazyLoadElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tPrettify2<Volatile & LazyLoadElysia['_ephemeral']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & LazyLoadElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, LazyLoadElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t/**\n\t * ### use\n\t * Merge separate logic of Elysia with current\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * const plugin = (app: Elysia) => app\n\t * .get('/plugin', () => 'hi')\n\t *\n\t * new Elysia()\n\t * .use(plugin)\n\t * ```\n\t */\n\tuse(\n\t\tplugin:\n\t\t\t| MaybePromise<AnyElysia>\n\t\t\t| MaybePromise<\n\t\t\t\t\tAnyElysia | ((app: AnyElysia) => MaybePromise<AnyElysia>)\n\t\t\t >\n\t\t\t| Promise<{\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t| AnyElysia\n\t\t\t\t\t\t| ((app: AnyElysia) => MaybePromise<AnyElysia>)\n\t\t\t }>,\n\t\toptions?: { scoped?: boolean }\n\t): AnyElysia {\n\t\tif (options?.scoped)\n\t\t\treturn this.guard({}, (app) => app.use(plugin as any))\n\n\t\tif (Array.isArray(plugin)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\t\tlet current = this\n\n\t\t\tfor (const p of plugin) current = this.use(p) as any\n\n\t\t\treturn current\n\t\t}\n\n\t\tif (plugin instanceof Promise) {\n\t\t\tthis.promisedModules.add(\n\t\t\t\tplugin\n\t\t\t\t\t.then((plugin) => {\n\t\t\t\t\t\tif (typeof plugin === 'function') return plugin(this)\n\n\t\t\t\t\t\tif (plugin instanceof Elysia) return this._use(plugin)\n\n\t\t\t\t\t\tif (typeof plugin.default === 'function')\n\t\t\t\t\t\t\treturn plugin.default(this)\n\n\t\t\t\t\t\tif (plugin.default instanceof Elysia)\n\t\t\t\t\t\t\treturn this._use(plugin.default)\n\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t'Invalid plugin type. Expected Elysia instance, function, or module with \"default\" as Elysia instance or function that returns Elysia instance.'\n\t\t\t\t\t\t)\n\t\t\t\t\t})\n\t\t\t\t\t.then((x) => x.compile())\n\t\t\t)\n\t\t\treturn this\n\t\t}\n\n\t\treturn this._use(plugin)\n\t}\n\n\tprivate _use(\n\t\tplugin: AnyElysia | ((app: AnyElysia) => MaybePromise<AnyElysia>)\n\t) {\n\t\tif (typeof plugin === 'function') {\n\t\t\tconst instance = plugin(this as unknown as any) as unknown as any\n\t\t\tif (instance instanceof Promise) {\n\t\t\t\tthis.promisedModules.add(\n\t\t\t\t\tinstance\n\t\t\t\t\t\t.then((plugin) => {\n\t\t\t\t\t\t\tif (plugin instanceof Elysia) {\n\t\t\t\t\t\t\t\tthis.compile()\n\n\t\t\t\t\t\t\t\t// Recompile async plugin routes\n\t\t\t\t\t\t\t\tfor (const {\n\t\t\t\t\t\t\t\t\tmethod,\n\t\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\t\thandler,\n\t\t\t\t\t\t\t\t\thooks\n\t\t\t\t\t\t\t\t} of Object.values(plugin.router.history)) {\n\t\t\t\t\t\t\t\t\tthis.add(\n\t\t\t\t\t\t\t\t\t\tmethod,\n\t\t\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\t\t\thandler,\n\t\t\t\t\t\t\t\t\t\tmergeHook(\n\t\t\t\t\t\t\t\t\t\t\thooks as LocalHook<\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany\n\t\t\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\terror: plugin.event.error\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn plugin\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (typeof plugin === 'function')\n\t\t\t\t\t\t\t\treturn plugin(\n\t\t\t\t\t\t\t\t\tthis as unknown as any\n\t\t\t\t\t\t\t\t) as unknown as Elysia\n\n\t\t\t\t\t\t\tif (typeof plugin.default === 'function')\n\t\t\t\t\t\t\t\treturn plugin.default(\n\t\t\t\t\t\t\t\t\tthis as unknown as any\n\t\t\t\t\t\t\t\t) as unknown as Elysia\n\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn this._use(plugin)\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.then((x) => x.compile())\n\t\t\t\t)\n\t\t\t\treturn this as unknown as any\n\t\t\t}\n\n\t\t\treturn instance\n\t\t}\n\n\t\tif (plugin.promisedModules.size) {\n\t\t\tthis.promisedModules.add(\n\t\t\t\tplugin.modules\n\t\t\t\t\t.then(() => this._use(plugin))\n\t\t\t\t\t.then((x) => x.compile())\n\t\t\t)\n\t\t\treturn this\n\t\t}\n\n\t\tconst { name, seed } = plugin.config\n\n\t\tplugin.getServer = () => this.getServer()\n\n\t\t/**\n\t\t * Model and error is required for Swagger generation\n\t\t */\n\t\tplugin.model(this.definitions.type as any)\n\t\tplugin.error(this.definitions.error as any)\n\n\t\tconst isScoped = plugin.config.scoped as boolean\n\t\tif (isScoped) {\n\t\t\tif (name) {\n\t\t\t\tif (!(name in this.dependencies)) this.dependencies[name] = []\n\n\t\t\t\tconst current =\n\t\t\t\t\tseed !== undefined\n\t\t\t\t\t\t? checksum(name + JSON.stringify(seed))\n\t\t\t\t\t\t: 0\n\n\t\t\t\tif (\n\t\t\t\t\tthis.dependencies[name].some(\n\t\t\t\t\t\t({ checksum }) => current === checksum\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn this\n\n\t\t\t\tthis.dependencies[name].push(\n\t\t\t\t\t!this.config?.analytic\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies,\n\t\t\t\t\t\t\t\tstack: plugin.telemetry.stack,\n\t\t\t\t\t\t\t\troutes: plugin.router.history,\n\t\t\t\t\t\t\t\tdecorators: plugin.singleton.decorator,\n\t\t\t\t\t\t\t\tstore: plugin.singleton.store,\n\t\t\t\t\t\t\t\ttype: plugin.definitions.type,\n\t\t\t\t\t\t\t\terror: plugin.definitions.error,\n\t\t\t\t\t\t\t\tderive: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x.subType === 'derive')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.fn.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tresolve: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x.subType === 'derive')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.fn.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t }\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tplugin.extender.macros = this.extender.macros.concat(\n\t\t\t\tplugin.extender.macros\n\t\t\t)\n\n\t\t\tconst macroHashes = <(number | undefined)[]>[]\n\n\t\t\tfor (let i = 0; i < plugin.extender.macros.length; i++) {\n\t\t\t\tconst macro = this.extender.macros[i]\n\n\t\t\t\tif (macroHashes.includes(macro.checksum)) {\n\t\t\t\t\tplugin.extender.macros.splice(i, 1)\n\t\t\t\t\ti--\n\t\t\t\t}\n\n\t\t\t\tmacroHashes.push(macro.checksum)\n\t\t\t}\n\n\t\t\tplugin.onRequest((context) => {\n\t\t\t\tObject.assign(context, this.singleton.decorator)\n\t\t\t\tObject.assign(context.store, this.singleton.store)\n\t\t\t})\n\n\t\t\tif (plugin.event.trace.length)\n\t\t\t\tplugin.event.trace.push(...plugin.event.trace)\n\n\t\t\tif (!plugin.config.prefix)\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.\"\n\t\t\t\t)\n\n\t\t\tif (plugin.event.error.length)\n\t\t\t\tplugin.event.error.push(...this.event.error)\n\n\t\t\tif (plugin.config.aot) plugin.compile()\n\n\t\t\tif (isScoped === true && plugin.config.prefix) {\n\t\t\t\tthis.mount(plugin.config.prefix + '/', plugin.fetch)\n\n\t\t\t\t// Ensure that when using plugins routes are correctly showing up in the .routes property. Else plugins e.g. swagger will not correctly work.\n\t\t\t\t// This also avoids adding routes multiple times.\n\t\t\t\tfor (const route of plugin.router.history) {\n\t\t\t\t\tthis.routeTree.set(\n\t\t\t\t\t\troute.method + `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\tthis.router.history.length\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.router.history.push({\n\t\t\t\t\t\t...route,\n\t\t\t\t\t\tpath: `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\thooks: mergeHook(route.hooks, {\n\t\t\t\t\t\t\terror: this.event.error\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.mount(plugin.fetch)\n\n\t\t\t\tfor (const route of plugin.router.history) {\n\t\t\t\t\tthis.routeTree.set(\n\t\t\t\t\t\troute.method + `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\tthis.router.history.length\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.router.history.push({\n\t\t\t\t\t\t...route,\n\t\t\t\t\t\tpath: `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\thooks: mergeHook(route.hooks, {\n\t\t\t\t\t\t\terror: this.event.error\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this\n\t\t} else {\n\t\t\tthis.headers(plugin.setHeaders)\n\n\t\t\tplugin.reporter = this.reporter\n\t\t\tfor (const trace of plugin.event.trace)\n\t\t\t\tif (trace.scope && trace.scope !== 'local')\n\t\t\t\t\tthis.trace(trace as any)\n\n\t\t\tif (name) {\n\t\t\t\tif (!(name in this.dependencies)) this.dependencies[name] = []\n\n\t\t\t\tconst current =\n\t\t\t\t\tseed !== undefined\n\t\t\t\t\t\t? checksum(name + JSON.stringify(seed))\n\t\t\t\t\t\t: 0\n\n\t\t\t\tif (\n\t\t\t\t\t!this.dependencies[name].some(\n\t\t\t\t\t\t({ checksum }) => current === checksum\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthis.extender.macros = this.extender.macros.concat(\n\t\t\t\t\t\tplugin.extender.macros\n\t\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.extender.macros = this.extender.macros.concat(\n\t\t\t\t\tplugin.extender.macros\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst macroHashes: number[] = []\n\n\t\t\tfor (let i = 0; i < this.extender.macros.length; i++) {\n\t\t\t\tconst macro = this.extender.macros[i]\n\n\t\t\t\tif (macro.checksum) {\n\t\t\t\t\tif (macroHashes.includes(macro.checksum)) {\n\t\t\t\t\t\tthis.extender.macros.splice(i, 1)\n\t\t\t\t\t\ti--\n\t\t\t\t\t}\n\n\t\t\t\t\tmacroHashes.push(macro.checksum)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.inference = {\n\t\t\t\tevent: {\n\t\t\t\t\tbody:\n\t\t\t\t\t\tthis.inference.event.body ||\n\t\t\t\t\t\tplugin.inference.event.body,\n\t\t\t\t\tcookie:\n\t\t\t\t\t\tthis.inference.event.cookie ||\n\t\t\t\t\t\tplugin.inference.event.cookie,\n\t\t\t\t\theaders:\n\t\t\t\t\t\tthis.inference.event.headers ||\n\t\t\t\t\t\tplugin.inference.event.headers,\n\t\t\t\t\tqueries: [\n\t\t\t\t\t\t...this.inference.event.queries,\n\t\t\t\t\t\t...plugin.inference.event.queries\n\t\t\t\t\t],\n\t\t\t\t\tquery:\n\t\t\t\t\t\tthis.inference.event.query ||\n\t\t\t\t\t\tplugin.inference.event.query,\n\t\t\t\t\tset: this.inference.event.set || plugin.inference.event.set,\n\t\t\t\t\tunknownQueries:\n\t\t\t\t\t\tthis.inference.event.unknownQueries ||\n\t\t\t\t\t\tplugin.inference.event.unknownQueries\n\t\t\t\t},\n\t\t\t\ttrace: {\n\t\t\t\t\trequest:\n\t\t\t\t\t\tthis.inference.trace.request ||\n\t\t\t\t\t\tplugin.inference.trace.request,\n\t\t\t\t\tparse:\n\t\t\t\t\t\tthis.inference.trace.parse ||\n\t\t\t\t\t\tplugin.inference.trace.parse,\n\t\t\t\t\ttransform:\n\t\t\t\t\t\tthis.inference.trace.transform ||\n\t\t\t\t\t\tplugin.inference.trace.transform,\n\t\t\t\t\thandle:\n\t\t\t\t\t\tthis.inference.trace.handle ||\n\t\t\t\t\t\tplugin.inference.trace.handle,\n\t\t\t\t\tbeforeHandle:\n\t\t\t\t\t\tthis.inference.trace.beforeHandle ||\n\t\t\t\t\t\tplugin.inference.trace.beforeHandle,\n\t\t\t\t\tafterHandle:\n\t\t\t\t\t\tthis.inference.trace.afterHandle ||\n\t\t\t\t\t\tplugin.inference.trace.afterHandle,\n\t\t\t\t\terror:\n\t\t\t\t\t\tthis.inference.trace.error ||\n\t\t\t\t\t\tplugin.inference.trace.error,\n\t\t\t\t\tcontext:\n\t\t\t\t\t\tthis.inference.trace.context ||\n\t\t\t\t\t\tplugin.inference.trace.context,\n\t\t\t\t\tstore:\n\t\t\t\t\t\tthis.inference.trace.store ||\n\t\t\t\t\t\tplugin.inference.trace.store,\n\t\t\t\t\tset: this.inference.trace.set || plugin.inference.trace.set\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.decorate(plugin.singleton.decorator)\n\t\tthis.state(plugin.singleton.store)\n\t\tthis.model(plugin.definitions.type)\n\t\tthis.error(plugin.definitions.error as any)\n\n\t\tfor (const { method, path, handler, hooks } of Object.values(\n\t\t\tplugin.router.history\n\t\t)) {\n\t\t\tthis.add(\n\t\t\t\tmethod,\n\t\t\t\tpath,\n\t\t\t\thandler,\n\t\t\t\tmergeHook(\n\t\t\t\t\thooks as LocalHook<any, any, any, any, any, any, any>,\n\t\t\t\t\t{\n\t\t\t\t\t\terror: plugin.event.error\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\n\t\tif (!isScoped)\n\t\t\tif (name) {\n\t\t\t\tif (!(name in this.dependencies)) this.dependencies[name] = []\n\n\t\t\t\tconst current =\n\t\t\t\t\tseed !== undefined\n\t\t\t\t\t\t? checksum(name + JSON.stringify(seed))\n\t\t\t\t\t\t: 0\n\n\t\t\t\tif (\n\t\t\t\t\tthis.dependencies[name].some(\n\t\t\t\t\t\t({ checksum }) => current === checksum\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn this\n\n\t\t\t\tthis.dependencies[name].push(\n\t\t\t\t\t!this.config?.analytic\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies,\n\t\t\t\t\t\t\t\tstack: plugin.telemetry.stack,\n\t\t\t\t\t\t\t\troutes: plugin.router.history,\n\t\t\t\t\t\t\t\tdecorators: plugin.singleton,\n\t\t\t\t\t\t\t\tstore: plugin.singleton.store,\n\t\t\t\t\t\t\t\ttype: plugin.definitions.type,\n\t\t\t\t\t\t\t\terror: plugin.definitions.error,\n\t\t\t\t\t\t\t\tderive: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x?.subType === 'derive')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tresolve: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x?.subType === 'resolve')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t }\n\t\t\t\t)\n\n\t\t\t\tthis.event = mergeLifeCycle(\n\t\t\t\t\tthis.event,\n\t\t\t\t\tfilterGlobalHook(plugin.event),\n\t\t\t\t\tcurrent\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.event = mergeLifeCycle(\n\t\t\t\t\tthis.event,\n\t\t\t\t\tfilterGlobalHook(plugin.event)\n\t\t\t\t)\n\t\t\t}\n\n\t\treturn this\n\t}\n\n\tmacro<const NewMacro extends BaseMacro>(\n\t\tmacro: (\n\t\t\troute: MacroManager<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Partial<Ephemeral['derive'] & Volatile['derive']>\n\t\t\t\t\tresolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>\n\t\t\t\t},\n\t\t\t\tDefinitions['error']\n\t\t\t>\n\t\t) => NewMacro\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\t{\n\t\t\tschema: Metadata['schema']\n\t\t\tmacro: Metadata['macro'] & Partial<MacroToProperty<NewMacro>>\n\t\t},\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tconst hook: MacroQueue = {\n\t\t\tchecksum: checksum(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tname: this.config.name,\n\t\t\t\t\tseed: this.config.seed,\n\t\t\t\t\tcontent: macro.toString()\n\t\t\t\t})\n\t\t\t),\n\t\t\tfn: macro as any\n\t\t}\n\n\t\tthis.extender.macros.push(hook)\n\n\t\treturn this as any\n\t}\n\n\tmount(\n\t\thandle: ((request: Request) => MaybePromise<Response>) | AnyElysia\n\t): this\n\tmount(\n\t\tpath: string,\n\t\thandle: ((request: Request) => MaybePromise<Response>) | AnyElysia\n\t): this\n\n\tmount(\n\t\tpath:\n\t\t\t| string\n\t\t\t| ((request: Request) => MaybePromise<Response>)\n\t\t\t| AnyElysia,\n\t\thandle?: ((request: Request) => MaybePromise<Response>) | AnyElysia\n\t) {\n\t\tif (\n\t\t\tpath instanceof Elysia ||\n\t\t\ttypeof path === 'function' ||\n\t\t\tpath.length === 0 ||\n\t\t\tpath === '/'\n\t\t) {\n\t\t\tconst run =\n\t\t\t\ttypeof path === 'function'\n\t\t\t\t\t? path\n\t\t\t\t\t: path instanceof Elysia\n\t\t\t\t\t? path.compile().fetch\n\t\t\t\t\t: handle instanceof Elysia\n\t\t\t\t\t? handle.compile().fetch\n\t\t\t\t\t: handle!\n\n\t\t\tconst handler: Handler<any, any> = async ({ request, path }) =>\n\t\t\t\trun(\n\t\t\t\t\tnew Request(\n\t\t\t\t\t\treplaceUrlPath(request.url, path || '/'),\n\t\t\t\t\t\trequest\n\t\t\t\t\t)\n\t\t\t\t)\n\n\t\t\tthis.all(\n\t\t\t\t'/*',\n\t\t\t\thandler as any,\n\t\t\t\t{\n\t\t\t\t\ttype: 'none'\n\t\t\t\t} as any\n\t\t\t)\n\n\t\t\treturn this\n\t\t}\n\n\t\tconst length = path.length\n\n\t\tif (handle instanceof Elysia) handle = handle.compile().fetch\n\n\t\tconst handler: Handler<any, any> = async ({ request, path }) =>\n\t\t\t(handle as Function)!(\n\t\t\t\tnew Request(\n\t\t\t\t\treplaceUrlPath(request.url, path.slice(length) || '/'),\n\t\t\t\t\trequest\n\t\t\t\t)\n\t\t\t)\n\n\t\tthis.all(\n\t\t\tpath,\n\t\t\thandler as any,\n\t\t\t{\n\t\t\t\ttype: 'none'\n\t\t\t} as any\n\t\t)\n\n\t\tthis.all(\n\t\t\tpath + (path.endsWith('/') ? '*' : '/*'),\n\t\t\thandler as any,\n\t\t\t{\n\t\t\t\ttype: 'none'\n\t\t\t} as any\n\t\t)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### get\n\t * Register handler for path with method [GET]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .get('/', () => 'hi')\n\t * .get('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tget<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tget: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('GET', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### post\n\t * Register handler for path with method [POST]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .post('/', () => 'hi')\n\t * .post('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tpost<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tpost: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('POST', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### put\n\t * Register handler for path with method [PUT]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .put('/', () => 'hi')\n\t * .put('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tput<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tput: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('PUT', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### patch\n\t * Register handler for path with method [PATCH]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .patch('/', () => 'hi')\n\t * .patch('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tpatch<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tpatch: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('PATCH', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### delete\n\t * Register handler for path with method [DELETE]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .delete('/', () => 'hi')\n\t * .delete('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tdelete<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tdelete: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('DELETE', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### options\n\t * Register handler for path with method [POST]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .options('/', () => 'hi')\n\t * .options('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\toptions<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('OPTIONS', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### all\n\t * Register handler for path with method [ALL]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .all('/', () => 'hi')\n\t * .all('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tall<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\t[method in string]: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('ALL', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### head\n\t * Register handler for path with method [HEAD]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .head('/', () => 'hi')\n\t * .head('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\thead<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\thead: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('HEAD', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### connect\n\t * Register handler for path with method [CONNECT]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .connect('/', () => 'hi')\n\t * .connect('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tconnect<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tconnect: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('CONNECT', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### route\n\t * Register handler for path with method [ROUTE]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .route('/', () => 'hi')\n\t * .route('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\troute<\n\t\tconst Method extends HTTPMethod,\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tmethod: Method,\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t> & {\n\t\t\tconfig: {\n\t\t\t\tallowMeta?: boolean\n\t\t\t}\n\t\t}\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\t[method in Method]: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add(method.toUpperCase(), path, handler as any, hook, hook?.config)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### ws\n\t * Register handler for path with method [ws]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .ws('/', {\n\t * message(ws, message) {\n\t * ws.send(message)\n\t * }\n\t * })\n\t * ```\n\t */\n\tws<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\toptions: WS.LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tsubscribe: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: Schema['response']\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tconst transform = options.transformMessage\n\t\t\t? Array.isArray(options.transformMessage)\n\t\t\t\t? options.transformMessage\n\t\t\t\t: [options.transformMessage]\n\t\t\t: undefined\n\n\t\tlet server: Server | null = null\n\n\t\tconst validateMessage = getSchemaValidator(options?.body, {\n\t\t\tmodels: this.definitions.type as Record<string, TSchema>,\n\t\t\tnormalize: this.config.normalize\n\t\t})\n\n\t\tconst validateResponse = getSchemaValidator(options?.response as any, {\n\t\t\tmodels: this.definitions.type as Record<string, TSchema>,\n\t\t\tnormalize: this.config.normalize\n\t\t})\n\n\t\tconst parseMessage = (message: any) => {\n\t\t\tif (typeof message === 'string') {\n\t\t\t\tconst start = message?.charCodeAt(0)\n\n\t\t\t\tif (start === 47 || start === 123)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tmessage = JSON.parse(message)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Not empty\n\t\t\t\t\t}\n\t\t\t\telse if (isNumericString(message)) message = +message\n\t\t\t}\n\n\t\t\tif (transform?.length)\n\t\t\t\tfor (let i = 0; i < transform.length; i++) {\n\t\t\t\t\tconst temp = transform[i](message)\n\n\t\t\t\t\tif (temp !== undefined) message = temp\n\t\t\t\t}\n\n\t\t\treturn message\n\t\t}\n\n\t\tthis.route(\n\t\t\t'$INTERNALWS',\n\t\t\tpath as any,\n\t\t\t// @ts-expect-error\n\t\t\t(context) => {\n\t\t\t\t// ! Enable static code analysis just in case resolveUnknownFunction doesn't work, do not remove\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\t\tconst { set, path, qi, headers, query, params } = context\n\n\t\t\t\tif (server === null) server = this.getServer()\n\n\t\t\t\tif (\n\t\t\t\t\tserver?.upgrade<any>(context.request, {\n\t\t\t\t\t\theaders: (typeof options.upgrade === 'function'\n\t\t\t\t\t\t\t? options.upgrade(context as any as Context)\n\t\t\t\t\t\t\t: options.upgrade) as Bun.HeadersInit,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tvalidator: validateResponse,\n\t\t\t\t\t\t\topen(ws: ServerWebSocket<any>) {\n\t\t\t\t\t\t\t\toptions.open?.(new ElysiaWS(ws, context as any))\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmessage: (ws: ServerWebSocket<any>, msg: any) => {\n\t\t\t\t\t\t\t\tconst message = parseMessage(msg)\n\n\t\t\t\t\t\t\t\tif (validateMessage?.Check(message) === false)\n\t\t\t\t\t\t\t\t\treturn void ws.send(\n\t\t\t\t\t\t\t\t\t\tnew ValidationError(\n\t\t\t\t\t\t\t\t\t\t\t'message',\n\t\t\t\t\t\t\t\t\t\t\tvalidateMessage,\n\t\t\t\t\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t\t\t\t\t).message as string\n\t\t\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\t\toptions.message?.(\n\t\t\t\t\t\t\t\t\tnew ElysiaWS(ws, context as any),\n\t\t\t\t\t\t\t\t\tmessage as any\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdrain(ws: ServerWebSocket<any>) {\n\t\t\t\t\t\t\t\toptions.drain?.(\n\t\t\t\t\t\t\t\t\tnew ElysiaWS(ws, context as any)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tclose(\n\t\t\t\t\t\t\t\tws: ServerWebSocket<any>,\n\t\t\t\t\t\t\t\tcode: number,\n\t\t\t\t\t\t\t\treason: string\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\toptions.close?.(\n\t\t\t\t\t\t\t\t\tnew ElysiaWS(ws, context as any),\n\t\t\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t\t\treason\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t\t\treturn\n\n\t\t\t\tset.status = 400\n\n\t\t\t\treturn 'Expected a websocket connection'\n\t\t\t},\n\t\t\t{\n\t\t\t\tbeforeHandle: options.beforeHandle,\n\t\t\t\ttransform: options.transform,\n\t\t\t\theaders: options.headers,\n\t\t\t\tparams: options.params,\n\t\t\t\tquery: options.query\n\t\t\t} as any\n\t\t)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### state\n\t * Assign global mutatable state accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .state({ counter: 0 })\n\t * .get('/', (({ counter }) => ++counter)\n\t * ```\n\t */\n\tstate<const Name extends string | number | symbol, Value>(\n\t\tname: Name,\n\t\tvalue: Value\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Singleton['decorator']\n\t\t\tstore: Prettify<\n\t\t\t\tSingleton['store'] & {\n\t\t\t\t\t[name in Name]: Value\n\t\t\t\t}\n\t\t\t>\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### state\n\t * Assign global mutatable state accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .state('counter', 0)\n\t * .get('/', (({ counter }) => ++counter)\n\t * ```\n\t */\n\tstate<Store extends Record<string, unknown>>(\n\t\tstore: Store\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Singleton['decorator']\n\t\t\tstore: Prettify<Singleton['store'] & Store>\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tstate<NewStore extends Record<string, unknown>>(\n\t\tmapper: (decorators: Singleton['store']) => NewStore\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Singleton['decorator']\n\t\t\tstore: NewStore\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### state\n\t * Assign global mutatable state accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .state('counter', 0)\n\t * .get('/', (({ counter }) => ++counter)\n\t * ```\n\t */\n\tstate(\n\t\tname: string | number | symbol | Record<string, unknown> | Function,\n\t\tvalue?: unknown\n\t) {\n\t\tswitch (typeof name) {\n\t\t\tcase 'object':\n\t\t\t\tthis.singleton.store = mergeDeep(this.singleton.store, name)\n\n\t\t\t\treturn this as any\n\n\t\t\tcase 'function':\n\t\t\t\tthis.singleton.store = name(this.singleton.store)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\tif (!(name in this.singleton.store)) {\n\t\t\t// eslint-disable-next-line no-extra-semi\n\t\t\t;(\n\t\t\t\tthis.singleton.store as Record<\n\t\t\t\t\tstring | number | symbol,\n\t\t\t\t\tunknown\n\t\t\t\t>\n\t\t\t)[name] = value\n\t\t}\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### decorate\n\t * Define custom method to `Context` accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .decorate('getDate', () => Date.now())\n\t * .get('/', (({ getDate }) => getDate())\n\t * ```\n\t */\n\tdecorate<const Name extends string, const Value>(\n\t\tname: Name,\n\t\tvalue: Value\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Prettify<\n\t\t\t\tSingleton['decorator'] & {\n\t\t\t\t\t[name in Name]: Value\n\t\t\t\t}\n\t\t\t>\n\t\t\tstore: Singleton['store']\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### decorate\n\t * Define custom method to `Context` accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .decorate('getDate', () => Date.now())\n\t * .get('/', (({ getDate }) => getDate())\n\t * ```\n\t */\n\tdecorate<const NewDecorators extends Record<string, unknown>>(\n\t\tdecorators: NewDecorators\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Prettify<Singleton['decorator'] & NewDecorators>\n\t\t\tstore: Singleton['store']\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tdecorate<const NewDecorators extends Record<string, unknown>>(\n\t\tmapper: (decorators: Singleton['decorator']) => NewDecorators\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: NewDecorators\n\t\t\tstore: Singleton['store']\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### decorate\n\t * Define custom method to `Context` accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .decorate('getDate', () => Date.now())\n\t * .get('/', (({ getDate }) => getDate())\n\t * ```\n\t */\n\tdecorate(\n\t\tname: string | Record<string, unknown> | Function,\n\t\tvalue?: unknown\n\t) {\n\t\tswitch (typeof name) {\n\t\t\tcase 'object':\n\t\t\t\tthis.singleton.decorator = mergeDeep(\n\t\t\t\t\tthis.singleton.decorator,\n\t\t\t\t\tname\n\t\t\t\t)\n\n\t\t\t\treturn this as any\n\n\t\t\tcase 'function':\n\t\t\t\tthis.singleton.decorator = name(this.singleton.decorator)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\tif (!(name in this.singleton.decorator))\n\t\t\tthis.singleton.decorator[name] = value\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tderive<const Derivative extends Record<string, unknown>>(\n\t\ttransform: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton & {\n\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Derivative>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Prettify<\n\t\t\t\tVolatile['derive'] &\n\t\t\t\t\t// Exclude `return error`\n\t\t\t\t\tExcludeElysiaResponse<Derivative>\n\t\t\t>\n\t\t\tresolve: Volatile['resolve']\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tderive<\n\t\tconst Derivative extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\ttransform: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton &\n\t\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['derive']\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t }),\n\t\t\t\t\tBasePath\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Derivative>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tSingleton['resolve'] & ExcludeElysiaResponse<Derivative>\n\t\t\t\t\t>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] & ExcludeElysiaResponse<Derivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<Derivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\tderive(\n\t\toptionsOrTransform: { as?: LifeCycleType } | Function,\n\t\ttransform?: Function\n\t) {\n\t\tif (!transform) {\n\t\t\ttransform = optionsOrTransform as any\n\t\t\toptionsOrTransform = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'derive',\n\t\t\tfn: transform!\n\t\t}\n\n\t\treturn this.onTransform(optionsOrTransform as any, hook as any) as any\n\t}\n\n\tmodel<const Name extends string, const Model extends TSchema>(\n\t\tname: Name,\n\t\tmodel: Model\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Prettify<\n\t\t\t\tDefinitions['type'] & { [name in Name]: Static<Model> }\n\t\t\t>\n\t\t\terror: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tmodel<const Recorder extends Record<string, TSchema>>(\n\t\trecord: Recorder\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Prettify<\n\t\t\t\tDefinitions['type'] & {\n\t\t\t\t\t[key in keyof Recorder]: Static<Recorder[key]>\n\t\t\t\t}\n\t\t\t>\n\t\t\terror: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tmodel<const NewType extends Record<string, TSchema>>(\n\t\tmapper: (decorators: {\n\t\t\t[type in keyof Definitions['type']]: ReturnType<\n\t\t\t\ttypeof t.Unsafe<Definitions['type'][type]>\n\t\t\t>\n\t\t}) => NewType\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: { [x in keyof NewType]: Static<NewType[x]> }\n\t\t\terror: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tmodel(name: string | Record<string, TSchema> | Function, model?: TSchema) {\n\t\tswitch (typeof name) {\n\t\t\tcase 'object':\n\t\t\t\tObject.entries(name).forEach(([key, value]) => {\n\t\t\t\t\tif (!(key in this.definitions.type))\n\t\t\t\t\t\tthis.definitions.type[key] = value as TSchema\n\t\t\t\t})\n\n\t\t\t\treturn this\n\n\t\t\tcase 'function':\n\t\t\t\tthis.definitions.type = name(this.definitions.type)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\t;(this.definitions.type as Record<string, TSchema>)[name] = model!\n\n\t\treturn this as any\n\t}\n\n\tmapDerive<const NewDerivative extends Record<string, unknown>>(\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t) => MaybePromise<NewDerivative>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: NewDerivative\n\t\t\tresolve: Volatile['resolve']\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\tmapDerive<\n\t\tconst NewDerivative extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t }),\n\t\t\t\tBasePath\n\t\t\t>\n\t\t) => MaybePromise<NewDerivative>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tSingleton['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewDerivative>\n\t\t\t\t\t>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewDerivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewDerivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\tmapDerive(\n\t\toptionsOrDerive: { as?: LifeCycleType } | Function,\n\t\tmapper?: Function\n\t) {\n\t\tif (!mapper) {\n\t\t\tmapper = optionsOrDerive as any\n\t\t\toptionsOrDerive = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'derive',\n\t\t\tfn: mapper!\n\t\t}\n\n\t\treturn this.onTransform(optionsOrDerive as any, hook as any) as any\n\t}\n\n\taffix<\n\t\tconst Base extends 'prefix' | 'suffix',\n\t\tconst Type extends 'all' | 'decorator' | 'state' | 'model' | 'error',\n\t\tconst Word extends string\n\t>(\n\t\tbase: Base,\n\t\ttype: Type,\n\t\tword: Word\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Type extends 'decorator' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['decorator']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['decorator']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Singleton['decorator']>\n\t\t\t\t: Singleton['decorator']\n\t\t\tstore: Type extends 'state' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['store']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['store']>\n\t\t\t\t\t: AddSuffix<Word, Singleton['store']>\n\t\t\t\t: Singleton['store']\n\t\t\tderive: Type extends 'decorator' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['derive']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['derive']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Singleton['derive']>\n\t\t\t\t: Singleton['derive']\n\t\t\tresolve: Type extends 'decorator' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['resolve']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['resolve']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Singleton['resolve']>\n\t\t\t\t: Singleton['resolve']\n\t\t},\n\t\t{\n\t\t\ttype: Type extends 'model' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Definitions['type']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Definitions['type']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Definitions['type']>\n\t\t\t\t: Definitions['type']\n\t\t\terror: Type extends 'error' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Definitions['error']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Definitions['error']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Definitions['error']>\n\t\t\t\t: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tif (word === '') return this as any\n\n\t\tconst delimieter = ['_', '-', ' ']\n\t\tconst capitalize = (word: string) =>\n\t\t\tword[0].toUpperCase() + word.slice(1)\n\n\t\tconst joinKey =\n\t\t\tbase === 'prefix'\n\t\t\t\t? (prefix: string, word: string) =>\n\t\t\t\t\t\tdelimieter.includes(prefix.at(-1) ?? '')\n\t\t\t\t\t\t\t? prefix + word\n\t\t\t\t\t\t\t: prefix + capitalize(word)\n\t\t\t\t: delimieter.includes(word.at(-1) ?? '')\n\t\t\t\t? (suffix: string, word: string) => word + suffix\n\t\t\t\t: (suffix: string, word: string) => word + capitalize(suffix)\n\n\t\tconst remap = (type: 'decorator' | 'state' | 'model' | 'error') => {\n\t\t\tconst store: Record<string, any> = {}\n\n\t\t\tswitch (type) {\n\t\t\t\tcase 'decorator':\n\t\t\t\t\tfor (const key in this.singleton.decorator) {\n\t\t\t\t\t\tstore[joinKey(word, key)] =\n\t\t\t\t\t\t\tthis.singleton.decorator[key]\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.singleton.decorator = store\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'state':\n\t\t\t\t\tfor (const key in this.singleton.store)\n\t\t\t\t\t\tstore[joinKey(word, key)] = this.singleton.store[key]\n\n\t\t\t\t\tthis.singleton.store = store\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'model':\n\t\t\t\t\tfor (const key in this.definitions.type)\n\t\t\t\t\t\tstore[joinKey(word, key)] = this.definitions.type[key]\n\n\t\t\t\t\tthis.definitions.type = store\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'error':\n\t\t\t\t\tfor (const key in this.definitions.error)\n\t\t\t\t\t\tstore[joinKey(word, key)] = this.definitions.error[key]\n\n\t\t\t\t\tthis.definitions.error = store\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst types = Array.isArray(type) ? type : [type]\n\n\t\tfor (const type of types.some((x) => x === 'all')\n\t\t\t? ['decorator', 'state', 'model', 'error']\n\t\t\t: types)\n\t\t\tremap(type as 'decorator')\n\n\t\treturn this as any\n\t}\n\n\tprefix<\n\t\tconst Type extends 'all' | 'decorator' | 'state' | 'model' | 'error',\n\t\tconst Word extends string\n\t>(type: Type, word: Word) {\n\t\treturn this.affix('prefix', type, word)\n\t}\n\n\tsuffix<\n\t\tconst Type extends 'all' | 'decorator' | 'state' | 'model' | 'error',\n\t\tconst Word extends string\n\t>(type: Type, word: Word) {\n\t\treturn this.affix('suffix', type, word)\n\t}\n\n\tcompile() {\n\t\tthis.fetch = this.config.aot\n\t\t\t? composeGeneralHandler(this)\n\t\t\t: createDynamicHandler(this)\n\n\t\tif (typeof this.server?.reload === 'function')\n\t\t\tthis.server.reload({\n\t\t\t\t...(this.server || {}),\n\t\t\t\tfetch: this.fetch\n\t\t\t})\n\n\t\treturn this\n\t}\n\n\thandle = async (request: Request) => this.fetch(request)\n\n\t/**\n\t * Use handle can be either sync or async to save performance.\n\t *\n\t * Beside benchmark purpose, please use 'handle' instead.\n\t */\n\tfetch = (request: Request): MaybePromise<Response> => {\n\t\tif (process.env.NODE_ENV === 'production' && this.config.aot !== false)\n\t\t\tconsole.warn(\n\t\t\t\t\"Performance degradation found. Please call Elysia.compile() before using 'fetch'\"\n\t\t\t)\n\n\t\treturn (this.fetch = this.config.aot\n\t\t\t? composeGeneralHandler(this)\n\t\t\t: createDynamicHandler(this))(request)\n\t}\n\n\tprivate handleError = async (\n\t\tcontext: Partial<\n\t\t\tContext<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t> & {\n\t\t\trequest: Request\n\t\t},\n\t\terror:\n\t\t\t| Error\n\t\t\t| ValidationError\n\t\t\t| ParseError\n\t\t\t| NotFoundError\n\t\t\t| InternalServerError\n\t) =>\n\t\t(this.handleError = this.config.aot\n\t\t\t? composeErrorHandler(this)\n\t\t\t: createDynamicErrorHandler(this))(context, error)\n\n\tprivate outerErrorHandler = (error: Error) =>\n\t\tnew Response(error.message || error.name || 'Error', {\n\t\t\t// @ts-ignore\n\t\t\tstatus: error?.status ?? 500\n\t\t})\n\n\t/**\n\t * ### listen\n\t * Assign current instance to port and start serving\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .get(\"/\", () => 'hi')\n\t * .listen(3000)\n\t * ```\n\t */\n\tlisten = (\n\t\toptions: string | number | Partial<Serve>,\n\t\tcallback?: ListenCallback\n\t) => {\n\t\tif (typeof Bun === 'undefined')\n\t\t\tthrow new Error(\n\t\t\t\t'.listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch'\n\t\t\t)\n\n\t\tthis.compile()\n\n\t\tif (typeof options === 'string') {\n\t\t\tif (!isNumericString(options))\n\t\t\t\tthrow new Error('Port must be a numeric value')\n\n\t\t\toptions = parseInt(options)\n\t\t}\n\n\t\tconst fetch = this.fetch\n\n\t\tconst serve =\n\t\t\ttypeof options === 'object'\n\t\t\t\t? ({\n\t\t\t\t\t\tdevelopment: !isProduction,\n\t\t\t\t\t\treusePort: true,\n\t\t\t\t\t\t...(this.config.serve || {}),\n\t\t\t\t\t\t...(options || {}),\n\t\t\t\t\t\twebsocket: {\n\t\t\t\t\t\t\t...(this.config.websocket || {}),\n\t\t\t\t\t\t\t...(websocket || {})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tfetch,\n\t\t\t\t\t\terror: this.outerErrorHandler\n\t\t\t\t } as Serve)\n\t\t\t\t: ({\n\t\t\t\t\t\tdevelopment: !isProduction,\n\t\t\t\t\t\treusePort: true,\n\t\t\t\t\t\t...(this.config.serve || {}),\n\t\t\t\t\t\twebsocket: {\n\t\t\t\t\t\t\t...(this.config.websocket || {}),\n\t\t\t\t\t\t\t...(websocket || {})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tport: options,\n\t\t\t\t\t\tfetch,\n\t\t\t\t\t\terror: this.outerErrorHandler\n\t\t\t\t } as Serve)\n\n\t\tthis.server = Bun?.serve(serve)\n\n\t\tfor (let i = 0; i < this.event.start.length; i++)\n\t\t\tthis.event.start[i].fn(this)\n\n\t\tif (callback) callback(this.server!)\n\n\t\tprocess.on('beforeExit', () => {\n\t\t\tif (this.server) {\n\t\t\t\tthis.server.stop()\n\t\t\t\tthis.server = null\n\n\t\t\t\tfor (let i = 0; i < this.event.stop.length; i++)\n\t\t\t\t\tthis.event.stop[i].fn(this)\n\t\t\t}\n\t\t})\n\n\t\tthis.promisedModules.then(() => {\n\t\t\tBun?.gc(false)\n\t\t})\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### stop\n\t * Stop server from serving\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * const app = new Elysia()\n\t * .get(\"/\", () => 'hi')\n\t * .listen(3000)\n\t *\n\t * // Sometime later\n\t * app.stop()\n\t * ```\n\t */\n\tstop = async () => {\n\t\tif (!this.server)\n\t\t\tthrow new Error(\n\t\t\t\t\"Elysia isn't running. Call `app.listen` to start the server.\"\n\t\t\t)\n\n\t\tif (this.server) {\n\t\t\tthis.server.stop()\n\t\t\tthis.server = null\n\n\t\t\tif (this.event.stop.length)\n\t\t\t\tfor (let i = 0; i < this.event.stop.length; i++)\n\t\t\t\t\tthis.event.stop[i].fn(this)\n\t\t}\n\t}\n\n\t/**\n\t * Wait until all lazy loaded modules all load is fully\n\t */\n\tget modules() {\n\t\treturn Promise.all(this.promisedModules.promises)\n\t}\n}\n\nexport { Elysia }\n\nexport { mapResponse, mapCompactResponse, mapEarlyResponse } from './handler'\nexport { t } from './type-system'\nexport { Cookie, type CookieOptions } from './cookies'\n\nexport {\n\tgetSchemaValidator,\n\tmergeHook,\n\tmergeObjectArray,\n\tgetResponseSchemaValidator,\n\tStatusMap,\n\tInvertedStatusMap\n} from './utils'\n\nexport {\n\terror,\n\tParseError,\n\tNotFoundError,\n\tValidationError,\n\tInternalServerError,\n\tInvalidCookieSignature,\n\tERROR_CODE,\n\tELYSIA_RESPONSE\n} from './error'\n\nexport type { Context, PreContext } from './context'\n\nexport type {\n\tEphemeralType,\n\tCreateEden,\n\tComposeElysiaResponse,\n\tElysiaConfig,\n\tSingletonBase,\n\tDefinitionBase,\n\tRouteBase,\n\tHandler,\n\tComposedHandler,\n\tInputSchema,\n\tLocalHook,\n\tMergeSchema,\n\tRouteSchema,\n\tUnwrapRoute,\n\tInternalRoute,\n\tHTTPMethod,\n\tSchemaValidator,\n\tVoidHandler,\n\tPreHandler,\n\tBodyHandler,\n\tOptionalHandler,\n\tErrorHandler,\n\tAfterHandler,\n\tLifeCycleEvent,\n\tTraceEvent,\n\tLifeCycleStore,\n\tLifeCycleType,\n\tMaybePromise,\n\tListenCallback,\n\tUnwrapSchema,\n\tTraceHandler,\n\tTraceProcess,\n\tTraceReporter,\n\tTraceStream,\n\tChecksum,\n\tDocumentDecoration\n} from './types'\n\nexport type { Static, TSchema } from '@sinclair/typebox'\n"
32
+ "import type { Serve, Server, ServerWebSocket } from 'bun'\n\nimport { Memoirist } from 'memoirist'\nimport EventEmitter from 'eventemitter3'\nimport { type Static, type TSchema } from '@sinclair/typebox'\n\nimport { createTraceListener } from './trace'\nimport type { Context } from './context'\n\nimport { t, TypeCheck } from './type-system'\nimport { sucrose, sucroseTrace, type Sucrose } from './sucrose'\n\nimport { ElysiaWS, websocket } from './ws'\nimport type { WS } from './ws/types'\n\nimport {\n\tcloneInference,\n\tfnToContainer,\n\tlocalHookToLifeCycleStore,\n\tmergeDeep,\n\tPromiseGroup\n} from './utils'\nimport {\n\tcomposeHandler,\n\tcomposeGeneralHandler,\n\tcomposeErrorHandler,\n\tjitRoute\n} from './compose'\nimport {\n\tmergeHook,\n\tgetSchemaValidator,\n\tgetResponseSchemaValidator,\n\tchecksum,\n\tmergeLifeCycle,\n\tfilterGlobalHook,\n\tasHookType,\n\ttraceBackMacro,\n\treplaceUrlPath,\n\tisNumericString,\n\tcreateMacroManager,\n\tgetCookieValidator\n} from './utils'\n\nimport {\n\tcreateDynamicErrorHandler,\n\tcreateDynamicHandler,\n\ttype DynamicHandler\n} from './dynamic-handle'\n\nimport {\n\tERROR_CODE,\n\tisProduction,\n\tValidationError,\n\ttype ParseError,\n\ttype NotFoundError,\n\ttype InternalServerError\n} from './error'\n\nimport type {\n\tElysiaConfig,\n\tSingletonBase,\n\tDefinitionBase,\n\tHandler,\n\tComposedHandler,\n\tInputSchema,\n\tLocalHook,\n\tMergeSchema,\n\tRouteSchema,\n\tUnwrapRoute,\n\tInternalRoute,\n\tHTTPMethod,\n\tSchemaValidator,\n\tVoidHandler,\n\tPreHandler,\n\tBodyHandler,\n\tOptionalHandler,\n\tAfterHandler,\n\tErrorHandler,\n\tLifeCycleStore,\n\tMaybePromise,\n\tPrettify,\n\tPrettify2,\n\tListenCallback,\n\tAddPrefix,\n\tAddSuffix,\n\tAddPrefixCapitalize,\n\tAddSuffixCapitalize,\n\tTraceReporter,\n\tTraceHandler,\n\tMaybeArray,\n\tGracefulHandler,\n\tGetPathParameter,\n\tMapResponse,\n\tChecksum,\n\tMacroManager,\n\tBaseMacro,\n\tMacroToProperty,\n\tTransformHandler,\n\tMetadataBase,\n\tRouteBase,\n\tCreateEden,\n\tComposeElysiaResponse,\n\tInlineHandler,\n\tHookContainer,\n\tLifeCycleType,\n\tMacroQueue,\n\tEphemeralType,\n\tExcludeElysiaResponse\n} from './types'\nimport { isNotEmpty } from './handler'\n\ntype AnyElysia = Elysia<any, any, any, any, any, any, any, any>\n\n/**\n * ### Elysia Server\n * Main instance to create web server using Elysia\n *\n * ---\n * @example\n * ```typescript\n * import { Elysia } from 'elysia'\n *\n * new Elysia()\n * .get(\"/\", () => \"Hello\")\n * .listen(3000)\n * ```\n */\nexport default class Elysia<\n\tconst in out BasePath extends string = '',\n\tconst in out Scoped extends boolean = false,\n\tconst in out Singleton extends SingletonBase = {\n\t\tdecorator: {}\n\t\tstore: {}\n\t\tderive: {}\n\t\tresolve: {}\n\t},\n\tconst in out Definitions extends DefinitionBase = {\n\t\ttype: {}\n\t\terror: {}\n\t},\n\tconst in out Metadata extends MetadataBase = {\n\t\tschema: {}\n\t\tmacro: {}\n\t},\n\tconst out Routes extends RouteBase = {},\n\t// ? scoped\n\tconst in out Ephemeral extends EphemeralType = {\n\t\tderive: {}\n\t\tresolve: {}\n\t\tschema: {}\n\t},\n\t// ? local\n\tconst in out Volatile extends EphemeralType = {\n\t\tderive: {}\n\t\tresolve: {}\n\t\tschema: {}\n\t}\n> {\n\tconfig: ElysiaConfig<BasePath, Scoped>\n\n\tserver: Server | null = null\n\tprivate dependencies: Record<string, Checksum[]> = {}\n\tprivate reporter: TraceReporter = new EventEmitter()\n\n\t_routes: Routes = {} as any\n\n\t_types = {\n\t\tPrefix: '' as BasePath,\n\t\tScoped: false as Scoped,\n\t\tSingleton: {} as Singleton,\n\t\tDefinitions: {} as Definitions,\n\t\tMetadata: {} as Metadata\n\t}\n\n\t_ephemeral = {} as Ephemeral\n\t_volatile = {} as Volatile\n\n\tprotected singleton = {\n\t\tdecorator: {},\n\t\tstore: {},\n\t\tderive: {},\n\t\tresolve: {}\n\t} as Singleton\n\n\tget store(): Singleton['store'] {\n\t\treturn this.singleton.store\n\t}\n\n\tget decorator(): Singleton['decorator'] {\n\t\treturn this.singleton.decorator\n\t}\n\n\tget _scoped() {\n\t\treturn this.config.scoped as Scoped\n\t}\n\n\tprotected definitions = {\n\t\ttype: {} as Record<string, TSchema>,\n\t\terror: {} as Record<string, Error>\n\t}\n\n\tprotected extender = {\n\t\tmacros: <MacroQueue[]>[]\n\t}\n\n\tprotected validator: SchemaValidator | null = null\n\n\tevent: LifeCycleStore = {\n\t\tstart: [],\n\t\trequest: [],\n\t\tparse: [],\n\t\ttransform: [],\n\t\tbeforeHandle: [],\n\t\tafterHandle: [],\n\t\tmapResponse: [],\n\t\tonResponse: [],\n\t\ttrace: [],\n\t\terror: [],\n\t\tstop: []\n\t}\n\n\ttelemetry = {\n\t\tstack: undefined as string | undefined\n\t}\n\n\trouter = {\n\t\thttp: new Memoirist<ComposedHandler>(),\n\t\tws: new Memoirist<ComposedHandler>(),\n\t\t// Use in non-AOT mode\n\t\tdynamic: new Memoirist<DynamicHandler>(),\n\t\tstatic: {\n\t\t\thttp: {\n\t\t\t\thandlers: [] as ComposedHandler[],\n\t\t\t\tvariables: '',\n\t\t\t\tmap: {} as Record<\n\t\t\t\t\tstring,\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: string\n\t\t\t\t\t\tall?: string\n\t\t\t\t\t}\n\t\t\t\t>,\n\t\t\t\tall: ''\n\t\t\t},\n\t\t\t// Static WS Router is consists of pathname and websocket handler index to compose\n\t\t\tws: {} as Record<string, number>\n\t\t},\n\t\thistory: [] as InternalRoute[]\n\t}\n\n\tprotected inference: {\n\t\tevent: Sucrose.Inference\n\t\ttrace: Sucrose.TraceInference\n\t} = {\n\t\tevent: {\n\t\t\tbody: false,\n\t\t\tcookie: false,\n\t\t\theaders: false,\n\t\t\tqueries: [],\n\t\t\tquery: false,\n\t\t\tset: false,\n\t\t\tunknownQueries: false\n\t\t},\n\t\ttrace: {\n\t\t\trequest: false,\n\t\t\tparse: false,\n\t\t\ttransform: false,\n\t\t\thandle: false,\n\t\t\tbeforeHandle: false,\n\t\t\tafterHandle: false,\n\t\t\terror: false,\n\t\t\tcontext: false,\n\t\t\tstore: false,\n\t\t\tset: false\n\t\t}\n\t}\n\n\tprivate promisedModules = new PromiseGroup()\n\n\tconstructor(config?: ElysiaConfig<BasePath, Scoped>) {\n\t\tif (config?.tags) {\n\t\t\tif (!config.detail)\n\t\t\t\tconfig.detail = {\n\t\t\t\t\ttags: config.tags\n\t\t\t\t}\n\t\t\telse config.detail.tags = config.tags\n\t\t}\n\n\t\tthis.config = {\n\t\t\tforceErrorEncapsulation: true,\n\t\t\tprefix: '',\n\t\t\taot: true,\n\t\t\tstrictPath: false,\n\t\t\tglobal: false,\n\t\t\tcookie: {},\n\t\t\tanalytic: false,\n\t\t\t...config,\n\t\t\texperimental: config?.experimental ?? {},\n\t\t\tseed: config?.seed === undefined ? '' : config?.seed\n\t\t} as any\n\n\t\tif (config?.analytic && (config?.name || config?.seed !== undefined))\n\t\t\tthis.telemetry.stack = new Error().stack\n\t}\n\n\tprivate getServer() {\n\t\treturn this.server\n\t}\n\n\tget routes(): InternalRoute[] {\n\t\treturn this.router.history\n\t}\n\n\tprotected routeTree = new Map<string, number>()\n\n\tprivate applyMacro(\n\t\tlocalHook: LocalHook<any, any, any, any, any, any, any>\n\t) {\n\t\tif (this.extender.macros.length) {\n\t\t\tconst manage = createMacroManager({\n\t\t\t\tglobalHook: this.event,\n\t\t\t\tlocalHook\n\t\t\t})\n\n\t\t\tconst manager: MacroManager = {\n\t\t\t\tevents: {\n\t\t\t\t\tglobal: this.event,\n\t\t\t\t\tlocal: localHook\n\t\t\t\t},\n\t\t\t\tonParse: manage('parse') as any,\n\t\t\t\tonTransform: manage('transform') as any,\n\t\t\t\tonBeforeHandle: manage('beforeHandle') as any,\n\t\t\t\tonAfterHandle: manage('afterHandle') as any,\n\t\t\t\tonResponse: manage('onResponse') as any,\n\t\t\t\tmapResponse: manage('mapResponse') as any,\n\t\t\t\tonError: manage('error') as any\n\t\t\t}\n\n\t\t\tfor (const macro of this.extender.macros)\n\t\t\t\ttraceBackMacro(macro.fn(manager), localHook)\n\t\t}\n\t}\n\n\tprivate add(\n\t\tmethod: HTTPMethod,\n\t\tpath: string,\n\t\thandle: Handler<any, any, any> | any,\n\t\tlocalHook?: LocalHook<any, any, any, any, any, any>,\n\t\t{ allowMeta = false, skipPrefix = false } = {\n\t\t\tallowMeta: false as boolean | undefined,\n\t\t\tskipPrefix: false as boolean | undefined\n\t\t}\n\t) {\n\t\tlocalHook = localHookToLifeCycleStore(localHook)\n\n\t\tif (path !== '' && path.charCodeAt(0) !== 47) path = '/' + path\n\n\t\tif (this.config.prefix && !skipPrefix && !this.config.scoped)\n\t\t\tpath = this.config.prefix + path\n\n\t\tif (localHook?.type)\n\t\t\tswitch (localHook.type) {\n\t\t\t\tcase 'text':\n\t\t\t\t\tlocalHook.type = 'text/plain'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'json':\n\t\t\t\t\tlocalHook.type = 'application/json'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'formdata':\n\t\t\t\t\tlocalHook.type = 'multipart/form-data'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'urlencoded':\n\t\t\t\t\tlocalHook.type = 'application/x-www-form-urlencoded'\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'arrayBuffer':\n\t\t\t\t\tlocalHook.type = 'application/octet-stream'\n\t\t\t\t\tbreak\n\n\t\t\t\tdefault:\n\t\t\t\t\tbreak\n\t\t\t}\n\n\t\tconst models = this.definitions.type\n\n\t\tlet _body: TypeCheck<any> | undefined,\n\t\t\t_headers: TypeCheck<any> | undefined,\n\t\t\t_params: TypeCheck<any> | undefined,\n\t\t\t_query: TypeCheck<any> | undefined,\n\t\t\t_cookie: TypeCheck<any> | undefined,\n\t\t\t_response:\n\t\t\t\t| TypeCheck<any>\n\t\t\t\t| Record<string, TypeCheck<any>>\n\t\t\t\t| undefined\n\n\t\t// ? Clone is need because of JIT, so the context doesn't switch between instance\n\t\tconst dynamic = !this.config.aot\n\n\t\tconst cloned = {\n\t\t\tbody: localHook?.body ?? (this.validator?.body as any),\n\t\t\theaders: localHook?.headers ?? (this.validator?.headers as any),\n\t\t\tparams: localHook?.params ?? (this.validator?.params as any),\n\t\t\tquery: localHook?.query ?? (this.validator?.query as any),\n\t\t\tcookie: localHook?.cookie ?? (this.validator?.cookie as any),\n\t\t\tresponse: localHook?.response ?? (this.validator?.response as any)\n\t\t}\n\n\t\tconst cookieValidator = () =>\n\t\t\tcloned.cookie\n\t\t\t\t? getCookieValidator({\n\t\t\t\t\t\tvalidator: cloned.cookie,\n\t\t\t\t\t\tdefaultConfig: this.config.cookie,\n\t\t\t\t\t\tconfig: cloned.cookie?.config ?? {},\n\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\tmodels\n\t\t\t\t })\n\t\t\t\t: undefined\n\n\t\tconst normalize = this.config.normalize\n\n\t\tconst validator =\n\t\t\tthis.config.precompile === true ||\n\t\t\t(typeof this.config.precompile === 'object' &&\n\t\t\t\tthis.config.precompile.schema === true)\n\t\t\t\t? {\n\t\t\t\t\t\tbody: getSchemaValidator(cloned.body, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t}),\n\t\t\t\t\t\theaders: getSchemaValidator(cloned.headers, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tadditionalProperties: true\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tparams: getSchemaValidator(cloned.params, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tquery: getSchemaValidator(cloned.query, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcookie: cookieValidator(),\n\t\t\t\t\t\tresponse: getResponseSchemaValidator(cloned.response, {\n\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t})\n\t\t\t\t }\n\t\t\t\t: ({\n\t\t\t\t\t\tget body() {\n\t\t\t\t\t\t\tif (_body) return _body\n\n\t\t\t\t\t\t\treturn (_body = getSchemaValidator(cloned.body, {\n\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget headers() {\n\t\t\t\t\t\t\tif (_headers) return _headers\n\n\t\t\t\t\t\t\treturn getSchemaValidator(cloned.headers, {\n\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\t\tadditionalProperties: true\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget params() {\n\t\t\t\t\t\t\tif (_params) return _params\n\n\t\t\t\t\t\t\treturn (_params = getSchemaValidator(\n\t\t\t\t\t\t\t\tcloned.params,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\t\tmodels\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t))\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget query() {\n\t\t\t\t\t\t\tif (_query) return _query\n\n\t\t\t\t\t\t\treturn (_query = getSchemaValidator(cloned.query, {\n\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\tmodels\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget cookie() {\n\t\t\t\t\t\t\tif (_cookie) return _cookie\n\n\t\t\t\t\t\t\treturn (_cookie = cookieValidator())\n\t\t\t\t\t\t},\n\t\t\t\t\t\tget response() {\n\t\t\t\t\t\t\tif (_response) return _response\n\n\t\t\t\t\t\t\treturn (_response = getResponseSchemaValidator(\n\t\t\t\t\t\t\t\tcloned.response,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tdynamic,\n\t\t\t\t\t\t\t\t\tmodels,\n\t\t\t\t\t\t\t\t\tnormalize\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t))\n\t\t\t\t\t\t}\n\t\t\t\t } as any)\n\n\t\tconst loosePath = path.endsWith('/')\n\t\t\t? path.slice(0, path.length - 1)\n\t\t\t: path + '/'\n\n\t\t// ! Init default [] for hooks if undefined\n\t\tlocalHook = mergeHook(localHook, {}, { allowMacro: true })\n\n\t\tif (localHook.tags) {\n\t\t\tif (!localHook.detail)\n\t\t\t\tlocalHook.detail = {\n\t\t\t\t\ttags: localHook.tags\n\t\t\t\t}\n\t\t\telse localHook.detail.tags = localHook.tags\n\t\t}\n\n\t\tif (isNotEmpty(this.config.detail))\n\t\t\tlocalHook.detail = mergeDeep(\n\t\t\t\tObject.assign({}, this.config.detail!),\n\t\t\t\tlocalHook.detail\n\t\t\t)\n\n\t\tthis.applyMacro(localHook)\n\n\t\tconst hooks = mergeHook(this.event, localHook)\n\n\t\tif (this.config.aot === false) {\n\t\t\tthis.router.dynamic.add(method, path, {\n\t\t\t\tvalidator,\n\t\t\t\thooks,\n\t\t\t\tcontent: localHook?.type as string,\n\t\t\t\thandle\n\t\t\t})\n\n\t\t\tif (this.config.strictPath === false) {\n\t\t\t\tthis.router.dynamic.add(method, loosePath, {\n\t\t\t\t\tvalidator,\n\t\t\t\t\thooks,\n\t\t\t\t\tcontent: localHook?.type as string,\n\t\t\t\t\thandle\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tthis.router.history.push({\n\t\t\t\tmethod,\n\t\t\t\tpath,\n\t\t\t\tcomposed: null,\n\t\t\t\thandler: handle,\n\t\t\t\thooks: hooks as any\n\t\t\t})\n\n\t\t\treturn\n\t\t}\n\n\t\tlet composed:\n\t\t\t| ((context: Context<any, any, any>) => MaybePromise<Response>)\n\t\t\t| undefined = undefined\n\n\t\tconst shouldPrecompile =\n\t\t\tthis.config.precompile === true ||\n\t\t\t(typeof this.config.precompile === 'object' &&\n\t\t\t\tthis.config.precompile.compose === true)\n\n\t\tconst appInference = cloneInference(this.inference)\n\n\t\tconst mainHandler = shouldPrecompile\n\t\t\t? composeHandler({\n\t\t\t\t\tapp: this,\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod,\n\t\t\t\t\tlocalHook: mergeHook(localHook),\n\t\t\t\t\thooks,\n\t\t\t\t\tvalidator,\n\t\t\t\t\thandler: handle,\n\t\t\t\t\tallowMeta,\n\t\t\t\t\tappInference\n\t\t\t })\n\t\t\t: (((context: Context) => {\n\t\t\t\t\tif (composed) return composed(context)\n\n\t\t\t\t\treturn (composed = composeHandler({\n\t\t\t\t\t\tapp: this,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tlocalHook: mergeHook(localHook),\n\t\t\t\t\t\thooks,\n\t\t\t\t\t\tvalidator,\n\t\t\t\t\t\thandler: handle,\n\t\t\t\t\t\tallowMeta,\n\t\t\t\t\t\tappInference\n\t\t\t\t\t}) as any)(context)\n\t\t\t }) as ComposedHandler)\n\n\t\tif (!shouldPrecompile)\n\t\t\tmainHandler.compose = () => {\n\t\t\t\treturn (mainHandler.composed = composeHandler({\n\t\t\t\t\tapp: this,\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod,\n\t\t\t\t\tlocalHook: mergeHook(localHook),\n\t\t\t\t\thooks,\n\t\t\t\t\tvalidator,\n\t\t\t\t\thandler: handle,\n\t\t\t\t\tallowMeta,\n\t\t\t\t\tappInference\n\t\t\t\t}) as any)\n\t\t\t}\n\n\t\tlet routeIndex = this.router.history.length\n\n\t\tif (this.routeTree.has(method + path)) {\n\t\t\trouteIndex = this.router.history.findIndex(\n\t\t\t\t(route) => route.path === path && route.method === method\n\t\t\t)\n\n\t\t\tif (routeIndex !== -1) {\n\t\t\t\t// remove route previously defined\n\t\t\t\tconst removed = this.router.history.splice(routeIndex, 1)[0]\n\n\t\t\t\tif (\n\t\t\t\t\tremoved &&\n\t\t\t\t\tthis.routeTree.has(removed?.method + removed?.path)\n\t\t\t\t)\n\t\t\t\t\tthis.routeTree.delete(removed.method + removed.path)\n\t\t\t}\n\t\t}\n\n\t\tthis.routeTree.set(method + path, routeIndex)\n\t\tthis.router.history.push({\n\t\t\tmethod,\n\t\t\tpath,\n\t\t\tcomposed: mainHandler,\n\t\t\thandler: handle,\n\t\t\thooks: hooks as any\n\t\t})\n\n\t\tconst staticRouter = this.router.static.http\n\n\t\tif (method === '$INTERNALWS') {\n\t\t\tconst loose = this.config.strictPath\n\t\t\t\t? undefined\n\t\t\t\t: path.endsWith('/')\n\t\t\t\t? path.slice(0, path.length - 1)\n\t\t\t\t: path + '/'\n\n\t\t\tif (path.indexOf(':') === -1 && path.indexOf('*') === -1) {\n\t\t\t\tconst index = staticRouter.handlers.length\n\t\t\t\tstaticRouter.handlers.push(mainHandler)\n\n\t\t\t\tstaticRouter.variables += `const st${index} = staticRouter.handlers[${index}]\\n`\n\n\t\t\t\tthis.router.static.ws[path] = index\n\t\t\t\tif (loose) this.router.static.ws[loose] = index\n\t\t\t} else {\n\t\t\t\tthis.router.ws.add('ws', path, mainHandler)\n\t\t\t\tif (loose) this.router.ws.add('ws', loose, mainHandler)\n\t\t\t}\n\n\t\t\treturn\n\t\t}\n\n\t\tif (path.indexOf(':') === -1 && path.indexOf('*') === -1) {\n\t\t\tconst index = staticRouter.handlers.length\n\t\t\tstaticRouter.handlers.push(mainHandler)\n\n\t\t\tstaticRouter.variables += shouldPrecompile\n\t\t\t\t? `const st${index} = staticRouter.handlers[${index}]\\n`\n\t\t\t\t: `let st${index} = staticRouter.handlers[${index}]\\nlet stc${index}\\n`\n\n\t\t\tif (!staticRouter.map[path])\n\t\t\t\tstaticRouter.map[path] = {\n\t\t\t\t\tcode: ''\n\t\t\t\t}\n\n\t\t\tif (method === 'ALL')\n\t\t\t\tstaticRouter.map[path].all = shouldPrecompile\n\t\t\t\t\t? `default: return st${index}(ctx)\\n`\n\t\t\t\t\t: `default: ${jitRoute(index)}\\n`\n\t\t\telse\n\t\t\t\tstaticRouter.map[path].code = shouldPrecompile\n\t\t\t\t\t? `case '${method}': return st${index}(ctx)\\n${staticRouter.map[path].code}`\n\t\t\t\t\t: `case '${method}': ${jitRoute(index)}\\n${\n\t\t\t\t\t\t\tstaticRouter.map[path].code\n\t\t\t\t\t }`\n\n\t\t\tif (!this.config.strictPath) {\n\t\t\t\tif (!staticRouter.map[loosePath])\n\t\t\t\t\tstaticRouter.map[loosePath] = {\n\t\t\t\t\t\tcode: ''\n\t\t\t\t\t}\n\n\t\t\t\tif (method === 'ALL')\n\t\t\t\t\tstaticRouter.map[loosePath].all = shouldPrecompile\n\t\t\t\t\t\t? `default: return st${index}(ctx)\\n`\n\t\t\t\t\t\t: `default: ${jitRoute(index)}\\n`\n\t\t\t\telse\n\t\t\t\t\tstaticRouter.map[loosePath].code = shouldPrecompile\n\t\t\t\t\t\t? `case '${method}': return st${index}(ctx)\\n${staticRouter.map[loosePath].code}`\n\t\t\t\t\t\t: `case '${method}': ${jitRoute(index)}\\n${\n\t\t\t\t\t\t\t\tstaticRouter.map[loosePath].code\n\t\t\t\t\t\t }`\n\t\t\t}\n\t\t} else {\n\t\t\tthis.router.http.add(method, path, mainHandler)\n\n\t\t\tif (!this.config.strictPath)\n\t\t\t\tthis.router.http.add(\n\t\t\t\t\tmethod,\n\t\t\t\t\tpath.endsWith('/')\n\t\t\t\t\t\t? path.slice(0, path.length - 1)\n\t\t\t\t\t\t: path + '/',\n\t\t\t\t\tmainHandler\n\t\t\t\t)\n\t\t}\n\t}\n\n\tprivate setHeaders?: Context['set']['headers']\n\theaders(header: Context['set']['headers'] | undefined) {\n\t\tif (!header) return this\n\n\t\tif (!this.setHeaders) this.setHeaders = {}\n\n\t\tthis.setHeaders = mergeDeep(this.setHeaders, header)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### start | Life cycle event\n\t * Called after server is ready for serving\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onStart(({ url, port }) => {\n\t * console.log(\"Running at ${url}:${port}\")\n\t * })\n\t * .listen(3000)\n\t * ```\n\t */\n\tonStart(handler: MaybeArray<GracefulHandler<this>>) {\n\t\tthis.on('start', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### request | Life cycle event\n\t * Called on every new request is accepted\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onRequest(({ method, url }) => {\n\t * saveToAnalytic({ method, url })\n\t * })\n\t * ```\n\t */\n\tonRequest<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tPreHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t) {\n\t\tthis.on('request', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### parse | Life cycle event\n\t * Callback function to handle body parsing\n\t *\n\t * If truthy value is returned, will be assigned to `context.body`\n\t * Otherwise will skip the callback and look for the next one.\n\t *\n\t * Equivalent to Express's body parser\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onParse((request, contentType) => {\n\t * if(contentType === \"application/json\")\n\t * return request.json()\n\t * })\n\t * ```\n\t */\n\tonParse<const Schema extends RouteSchema>(\n\t\tparser: MaybeArray<\n\t\t\tBodyHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### parse | Life cycle event\n\t * Callback function to handle body parsing\n\t *\n\t * If truthy value is returned, will be assigned to `context.body`\n\t * Otherwise will skip the callback and look for the next one.\n\t *\n\t * Equivalent to Express's body parser\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onParse((request, contentType) => {\n\t * if(contentType === \"application/json\")\n\t * return request.json()\n\t * })\n\t * ```\n\t */\n\tonParse<const Schema extends RouteSchema, const Type extends LifeCycleType>(\n\t\toptions: { as?: Type },\n\t\tparser: MaybeArray<\n\t\t\tBodyHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonParse(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('parse', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'parse',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### transform | Life cycle event\n\t * Assign or transform anything related to context before validation.\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onTransform(({ params }) => {\n\t * if(params.id)\n\t * params.id = +params.id\n\t * })\n\t * ```\n\t */\n\tonTransform<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tTransformHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### transform | Life cycle event\n\t * Assign or transform anything related to context before validation.\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onTransform(({ params }) => {\n\t * if(params.id)\n\t * params.id = +params.id\n\t * })\n\t * ```\n\t */\n\tonTransform<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tTransformHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonTransform(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('transform', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'transform',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tresolve<\n\t\tconst Resolver extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\tresolver: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton &\n\t\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['derive']\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t })\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Resolver>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tSingleton['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t\t\t>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tresolve<const Resolver extends Record<string, unknown>>(\n\t\tresolver: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton & {\n\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t},\n\t\t\t\t\tBasePath\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Resolver>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Volatile['resolve']\n\t\t\tresolve: Prettify<\n\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<Resolver>\n\t\t\t>\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\tresolve(\n\t\toptionsOrResolve: { as?: LifeCycleType } | Function,\n\t\tresolve?: Function\n\t) {\n\t\tif (!resolve) {\n\t\t\tresolve = optionsOrResolve as any\n\t\t\toptionsOrResolve = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'resolve',\n\t\t\tfn: resolve!\n\t\t}\n\n\t\treturn this.onBeforeHandle(optionsOrResolve as any, hook as any) as any\n\t}\n\n\tmapResolve<const NewResolver extends Record<string, unknown>>(\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t) => MaybePromise<NewResolver>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Volatile['derive']\n\t\t\tresolve: NewResolver\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\tmapResolve<\n\t\tconst NewResolver extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t) => MaybePromise<NewResolver>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Awaited<NewResolver>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewResolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<NewResolver>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\tmapResolve(\n\t\toptionsOrResolve: Function | { as?: LifeCycleType },\n\t\tmapper?: Function\n\t) {\n\t\tif (!mapper) {\n\t\t\tmapper = optionsOrResolve as any\n\t\t\toptionsOrResolve = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'resolve',\n\t\t\tfn: mapper!\n\t\t}\n\n\t\treturn this.onBeforeHandle(optionsOrResolve as any, hook as any) as any\n\t}\n\n\t/**\n\t * ### Before Handle | Life cycle event\n\t * Execute after validation and before the main route handler.\n\t *\n\t * If truthy value is returned, will be assigned as `Response` and skip the main handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onBeforeHandle(({ params: { id }, status }) => {\n\t * if(id && !isExisted(id)) {\n\t * \t status(401)\n\t *\n\t * return \"Unauthorized\"\n\t * \t }\n\t * })\n\t * ```\n\t */\n\tonBeforeHandle<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tOptionalHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### Before Handle | Life cycle event\n\t * Execute after validation and before the main route handler.\n\t *\n\t * If truthy value is returned, will be assigned as `Response` and skip the main handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onBeforeHandle(({ params: { id }, status }) => {\n\t * if(id && !isExisted(id)) {\n\t * \t status(401)\n\t *\n\t * return \"Unauthorized\"\n\t * \t }\n\t * })\n\t * ```\n\t */\n\tonBeforeHandle<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tOptionalHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t }),\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\tonBeforeHandle(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('beforeHandle', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'beforeHandle',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tonAfterHandle<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tAfterHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tonAfterHandle<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: LifeCycleType },\n\t\thandler: MaybeArray<\n\t\t\tAfterHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonAfterHandle(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('afterHandle', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'afterHandle',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .mapResponse((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tmapResponse<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tMapResponse<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .mapResponse((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\tmapResponse<const Schema extends RouteSchema, Type extends LifeCycleType>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tMapResponse<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tmapResponse(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('mapResponse', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'mapResponse',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### response | Life cycle event\n\t * Called when handler is executed\n\t * Good for analytic metrics\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\n\tonResponse<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<\n\t\t\tVoidHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t): this\n\n\t/**\n\t * ### response | Life cycle event\n\t * Called when handler is executed\n\t * Good for analytic metrics\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\n\tonResponse<\n\t\tconst Schema extends RouteSchema,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\thandler: MaybeArray<\n\t\t\tVoidHandler<\n\t\t\t\tMergeSchema<\n\t\t\t\t\tSchema,\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema']\n\t\t\t\t>,\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t })\n\t\t\t>\n\t\t>\n\t): this\n\n\tonResponse(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('response', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'response',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\ttrace<const Schema extends RouteSchema>(\n\t\thandler: MaybeArray<TraceHandler<Schema, Singleton>>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\ttrace<const Schema extends RouteSchema>(\n\t\toptions: { as?: LifeCycleType },\n\t\thandler: MaybeArray<TraceHandler<Schema, Singleton>>\n\t): this\n\n\t/**\n\t * ### After Handle | Life cycle event\n\t * Intercept request **after** main handler is called.\n\t *\n\t * If truthy value is returned, will be assigned as `Response`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onAfterHandle((context, response) => {\n\t * if(typeof response === \"object\")\n\t * return JSON.stringify(response)\n\t * })\n\t * ```\n\t */\n\ttrace(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) {\n\t\t\thandler = options as MaybeArray<Function>\n\t\t\toptions = { as: 'local' }\n\t\t}\n\n\t\tif (!Array.isArray(handler)) handler = [handler] as Function[]\n\n\t\tfor (const fn of handler)\n\t\t\tthis.reporter.on(\n\t\t\t\t'event',\n\t\t\t\tcreateTraceListener(\n\t\t\t\t\t() => this.reporter,\n\t\t\t\t\tthis.event.trace.length,\n\t\t\t\t\tfn as any\n\t\t\t\t)\n\t\t\t)\n\n\t\tthis.on(options as { as?: LifeCycleType }, 'trace', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * Register errors\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * class CustomError extends Error {\n\t * constructor() {\n\t * super()\n\t * }\n\t * }\n\t *\n\t * new Elysia()\n\t * .error('CUSTOM_ERROR', CustomError)\n\t * ```\n\t */\n\terror<\n\t\tconst Errors extends Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tprototype: Error\n\t\t\t}\n\t\t>\n\t>(\n\t\terrors: Errors\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Definitions['type']\n\t\t\terror: Definitions['error'] & {\n\t\t\t\t[K in keyof Errors]: Errors[K] extends {\n\t\t\t\t\tprototype: infer LiteralError extends Error\n\t\t\t\t}\n\t\t\t\t\t? LiteralError\n\t\t\t\t\t: Errors[K]\n\t\t\t}\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * Register errors\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * class CustomError extends Error {\n\t * constructor() {\n\t * super()\n\t * }\n\t * }\n\t *\n\t * new Elysia()\n\t * .error({\n\t * CUSTOM_ERROR: CustomError\n\t * })\n\t * ```\n\t */\n\terror<\n\t\tName extends string,\n\t\tconst CustomError extends {\n\t\t\tprototype: Error\n\t\t}\n\t>(\n\t\tname: Name,\n\t\terrors: CustomError\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Definitions['type']\n\t\t\terror: Definitions['error'] & {\n\t\t\t\t[name in Name]: CustomError extends {\n\t\t\t\t\tprototype: infer LiteralError extends Error\n\t\t\t\t}\n\t\t\t\t\t? LiteralError\n\t\t\t\t\t: CustomError\n\t\t\t}\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * Register errors\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * class CustomError extends Error {\n\t * constructor() {\n\t * super()\n\t * }\n\t * }\n\t *\n\t * new Elysia()\n\t * .error('CUSTOM_ERROR', CustomError)\n\t * ```\n\t */\n\terror<const NewErrors extends Record<string, Error>>(\n\t\tmapper: (decorators: Definitions['error']) => NewErrors\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Definitions['type']\n\t\t\terror: {\n\t\t\t\t[K in keyof NewErrors]: NewErrors[K] extends {\n\t\t\t\t\tprototype: infer LiteralError extends Error\n\t\t\t\t}\n\t\t\t\t\t? LiteralError\n\t\t\t\t\t: never\n\t\t\t}\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\terror(\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tname:\n\t\t\t| string\n\t\t\t| Record<\n\t\t\t\t\tstring,\n\t\t\t\t\t{\n\t\t\t\t\t\tprototype: Error\n\t\t\t\t\t}\n\t\t\t >\n\t\t\t| Function,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\terror?: {\n\t\t\tprototype: Error\n\t\t}\n\t): AnyElysia {\n\t\tswitch (typeof name) {\n\t\t\tcase 'string':\n\t\t\t\t// @ts-ignore\n\t\t\t\terror.prototype[ERROR_CODE] = name\n\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.definitions.error[name] = error\n\n\t\t\t\treturn this\n\n\t\t\tcase 'function':\n\t\t\t\tthis.definitions.error = name(this.definitions.error)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\tfor (const [code, error] of Object.entries(name)) {\n\t\t\t// @ts-ignore\n\t\t\terror.prototype[ERROR_CODE] = code as any\n\n\t\t\tthis.definitions.error[code] = error as any\n\t\t}\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### Error | Life cycle event\n\t * Called when error is thrown during processing request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\tonError<const Schema extends RouteSchema>(\n\t\thandler: ErrorHandler<\n\t\t\tDefinitions['error'],\n\t\t\tMergeSchema<\n\t\t\t\tSchema,\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t\t>,\n\t\t\tSingleton\n\t\t>\n\t): this\n\n\t/**\n\t * ### Error | Life cycle event\n\t * Called when error is thrown during processing request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\tonError<const Schema extends RouteSchema>(\n\t\toptions: { as?: LifeCycleType },\n\t\thandler: ErrorHandler<\n\t\t\tDefinitions['error'],\n\t\t\tMergeSchema<\n\t\t\t\tSchema,\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t\t>,\n\t\t\tSingleton\n\t\t>\n\t): this\n\n\t/**\n\t * ### Error | Life cycle event\n\t * Called when error is thrown during processing request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onError(({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\tonError(\n\t\toptions: { as?: LifeCycleType } | MaybeArray<Function>,\n\t\thandler?: MaybeArray<Function>\n\t) {\n\t\tif (!handler) return this.on('error', options as any)\n\n\t\treturn this.on(\n\t\t\toptions as { as?: LifeCycleType },\n\t\t\t'error',\n\t\t\thandler as any\n\t\t)\n\t}\n\n\t/**\n\t * ### stop | Life cycle event\n\t * Called after server stop serving request\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .onStop((app) => {\n\t * cleanup()\n\t * })\n\t * ```\n\t */\n\tonStop(handler: MaybeArray<GracefulHandler<this>>) {\n\t\tthis.on('stop', handler as any)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### on\n\t * Syntax sugar for attaching life cycle event by name\n\t *\n\t * Does the exact same thing as `.on[Event]()`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .on('error', ({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\ton<Event extends keyof LifeCycleStore>(\n\t\ttype: Exclude<Event, 'onResponse'> | 'response',\n\t\thandlers: MaybeArray<\n\t\t\tExtract<LifeCycleStore[Event], HookContainer[]>[0]['fn']\n\t\t>\n\t): this\n\n\t/**\n\t * ### on\n\t * Syntax sugar for attaching life cycle event by name\n\t *\n\t * Does the exact same thing as `.on[Event]()`\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .on('error', ({ code }) => {\n\t * if(code === \"NOT_FOUND\")\n\t * return \"Path not found :(\"\n\t * })\n\t * ```\n\t */\n\ton<const Event extends keyof LifeCycleStore>(\n\t\toptions: { as?: LifeCycleType },\n\t\ttype: Exclude<Event, 'onResponse'> | 'response',\n\t\thandlers: MaybeArray<Extract<LifeCycleStore[Event], Function[]>[0]>\n\t): this\n\n\ton(\n\t\toptionsOrType: { as?: LifeCycleType } | string,\n\t\ttypeOrHandlers: MaybeArray<Function | HookContainer> | string,\n\t\thandlers?: MaybeArray<Function | HookContainer>\n\t) {\n\t\tlet type: Exclude<keyof LifeCycleStore, 'onResponse'> | 'onResponse'\n\n\t\tswitch (typeof optionsOrType) {\n\t\t\tcase 'string':\n\t\t\t\ttype = optionsOrType as any\n\t\t\t\thandlers = typeOrHandlers as any\n\n\t\t\t\tbreak\n\n\t\t\tcase 'object':\n\t\t\t\ttype = typeOrHandlers as any\n\t\t\t\tbreak\n\t\t}\n\n\t\t// @ts-expect-error possible user error, leave it on\n\t\tif (type === 'response') type = 'onResponse'\n\n\t\tif (Array.isArray(handlers)) handlers = fnToContainer(handlers)\n\t\telse {\n\t\t\tif (typeof handlers === 'function')\n\t\t\t\thandlers = [\n\t\t\t\t\t{\n\t\t\t\t\t\tfn: handlers\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\telse handlers = [handlers!]\n\t\t}\n\n\t\tconst handles = handlers as HookContainer[]\n\n\t\tfor (const handle of handles)\n\t\t\thandle.scope =\n\t\t\t\ttypeof optionsOrType === 'string'\n\t\t\t\t\t? 'local'\n\t\t\t\t\t: optionsOrType?.as ?? 'local'\n\n\t\tif (type === 'trace')\n\t\t\tsucroseTrace(\n\t\t\t\thandles.map((x) => x.fn) as TraceHandler[],\n\t\t\t\tthis.inference.trace\n\t\t\t)\n\t\telse\n\t\t\tsucrose(\n\t\t\t\t{\n\t\t\t\t\t[type]: handles.map((x) => x.fn)\n\t\t\t\t},\n\t\t\t\tthis.inference.event\n\t\t\t)\n\n\t\tfor (const handle of handles) {\n\t\t\tconst fn = asHookType(handle, 'global', { skipIfHasType: true })\n\n\t\t\tswitch (type) {\n\t\t\t\tcase 'start':\n\t\t\t\t\tthis.event.start.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'request':\n\t\t\t\t\tthis.event.request.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'parse':\n\t\t\t\t\tthis.event.parse.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'transform':\n\t\t\t\t\tthis.event.transform.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'beforeHandle':\n\t\t\t\t\tthis.event.beforeHandle.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'afterHandle':\n\t\t\t\t\tthis.event.afterHandle.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'mapResponse':\n\t\t\t\t\tthis.event.mapResponse.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'onResponse':\n\t\t\t\t\tthis.event.onResponse.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'trace':\n\t\t\t\t\tthis.event.trace.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'error':\n\t\t\t\t\tthis.event.error.push(fn as any)\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'stop':\n\t\t\t\t\tthis.event.stop.push(fn as any)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn this\n\t}\n\n\tpropagate(): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tPrettify2<Ephemeral & Volatile>,\n\t\t{\n\t\t\tderive: {}\n\t\t\tresolve: {}\n\t\t\tschema: {}\n\t\t}\n\t> {\n\t\t/**\n\t\t * Since it's a plugin, which means that ephemeral is demoted to volatile.\n\t\t * Which means there's no volatile and all previous ephemeral become volatile\n\t\t * We can just promote back without worry\n\t\t */\n\t\tconst promoteEvent = (events: (HookContainer | Function)[]) => {\n\t\t\tfor (const event of events) {\n\t\t\t\tif ('scope' in event && event.scope === 'local')\n\t\t\t\t\tevent.scope = 'scoped'\n\t\t\t}\n\t\t}\n\n\t\tpromoteEvent(this.event.parse)\n\t\tpromoteEvent(this.event.transform)\n\t\tpromoteEvent(this.event.beforeHandle)\n\t\tpromoteEvent(this.event.afterHandle)\n\t\tpromoteEvent(this.event.mapResponse)\n\t\tpromoteEvent(this.event.onResponse)\n\t\tpromoteEvent(this.event.trace)\n\t\tpromoteEvent(this.event.error)\n\n\t\treturn this as any\n\t}\n\n\tgroup<\n\t\tconst Prefix extends string,\n\t\tconst NewElysia extends Elysia<any, any, any, any, any, any, any, any>\n\t>(\n\t\tprefix: Prefix,\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\t`${BasePath}${Prefix}`,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tPrettify<Routes & NewElysia['_routes']>,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tgroup<\n\t\tconst Prefix extends string,\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Input extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<Input, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\tprefix: Prefix,\n\t\tschema: LocalHook<\n\t\t\tInput,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Prefix}`\n\t\t>,\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\t`${BasePath}${Prefix}`,\n\t\t\t\tfalse,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\t{\n\t\t\t\t\tschema: Schema\n\t\t\t\t\tmacro: Metadata['macro']\n\t\t\t\t},\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes & NewElysia['_routes'],\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### group\n\t * Encapsulate and group path with prefix\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .group('/v1', app => app\n\t * .get('/', () => 'Hi')\n\t * .get('/name', () => 'Elysia')\n\t * })\n\t * ```\n\t */\n\tgroup(\n\t\tprefix: string,\n\t\tschemaOrRun:\n\t\t\t| LocalHook<any, any, any, any, any, any>\n\t\t\t| ((group: AnyElysia) => AnyElysia),\n\t\trun?: (group: AnyElysia) => AnyElysia\n\t): AnyElysia {\n\t\tconst instance = new Elysia({\n\t\t\t...this.config,\n\t\t\tprefix: ''\n\t\t})\n\n\t\tinstance.singleton = { ...this.singleton }\n\t\tinstance.definitions = { ...this.definitions }\n\t\tinstance.getServer = () => this.server\n\t\tinstance.inference = cloneInference(this.inference)\n\n\t\tconst isSchema = typeof schemaOrRun === 'object'\n\t\tconst sandbox = (isSchema ? run! : schemaOrRun)(instance)\n\t\tthis.singleton = mergeDeep(this.singleton, instance.singleton) as any\n\t\tthis.definitions = mergeDeep(this.definitions, instance.definitions)\n\n\t\tif (sandbox.event.request.length)\n\t\t\tthis.event.request = [\n\t\t\t\t...(this.event.request || []),\n\t\t\t\t...((sandbox.event.request || []) as any)\n\t\t\t]\n\n\t\tif (sandbox.event.onResponse.length)\n\t\t\tthis.event.onResponse = [\n\t\t\t\t...(this.event.onResponse || []),\n\t\t\t\t...((sandbox.event.onResponse || []) as any)\n\t\t\t]\n\n\t\tthis.model(sandbox.definitions.type)\n\n\t\tObject.values(instance.router.history).forEach(\n\t\t\t({ method, path, handler, hooks }) => {\n\t\t\t\tpath = (isSchema ? '' : this.config.prefix) + prefix + path\n\n\t\t\t\tif (isSchema) {\n\t\t\t\t\tconst hook = schemaOrRun\n\t\t\t\t\tconst localHook = hooks as LocalHook<\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany,\n\t\t\t\t\t\tany\n\t\t\t\t\t>\n\n\t\t\t\t\tthis.add(\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\thandler,\n\t\t\t\t\t\tmergeHook(hook, {\n\t\t\t\t\t\t\t...(localHook || {}),\n\t\t\t\t\t\t\terror: !localHook.error\n\t\t\t\t\t\t\t\t? sandbox.event.error\n\t\t\t\t\t\t\t\t: Array.isArray(localHook.error)\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t...(localHook.error || {}),\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || {})\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\tlocalHook.error,\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || {})\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tthis.add(\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\thandler,\n\t\t\t\t\t\tmergeHook(\n\t\t\t\t\t\t\thooks as LocalHook<any, any, any, any, any, any>,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\terror: sandbox.event.error\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tskipPrefix: true\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t)\n\n\t\treturn this as any\n\t}\n\n\tguard<\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\thook: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\tBasePath\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Volatile['resolve']\n\t\t\tresolve: Volatile['resolve']\n\t\t\tschema: MergeSchema<\n\t\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t\t>\n\t\t}\n\t>\n\n\tguard<\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\t{\n\t\t\t\t\tschema: Prettify<Schema>\n\t\t\t\t\tmacro: Metadata['macro']\n\t\t\t\t},\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tPrettify<Routes & NewElysia['_routes']>,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tguard<\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tExtract<keyof Definitions['type'], string>\n\t\t>,\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\tschema: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t''\n\t\t>,\n\t\trun: (\n\t\t\tgroup: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\t{\n\t\t\t\t\tschema: Prettify<Schema>\n\t\t\t\t\tmacro: Metadata['macro']\n\t\t\t\t},\n\t\t\t\t{},\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t\t>\n\t\t) => NewElysia\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tPrettify<Routes & NewElysia['_routes']>,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### guard\n\t * Encapsulate and pass hook into all child handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .guard({\n\t * schema: {\n\t * body: t.Object({\n\t * username: t.String(),\n\t * password: t.String()\n\t * })\n\t * }\n\t * }, app => app\n\t * .get(\"/\", () => 'Hi')\n\t * .get(\"/name\", () => 'Elysia')\n\t * })\n\t * ```\n\t */\n\tguard(\n\t\thook:\n\t\t\t| LocalHook<any, any, any, any, any, any, any>\n\t\t\t| ((group: AnyElysia) => AnyElysia),\n\t\trun?: (group: AnyElysia) => AnyElysia\n\t): AnyElysia {\n\t\tif (!run) {\n\t\t\tif (typeof hook === 'object') {\n\t\t\t\tthis.applyMacro(hook)\n\t\t\t\tthis.event = mergeLifeCycle(this.event, hook)\n\t\t\t\tthis.validator = {\n\t\t\t\t\tbody: hook.body ?? this.validator?.body,\n\t\t\t\t\theaders: hook.headers ?? this.validator?.headers,\n\t\t\t\t\tparams: hook.params ?? this.validator?.params,\n\t\t\t\t\tquery: hook.query ?? this.validator?.query,\n\t\t\t\t\tresponse: hook.response ?? this.validator?.response,\n\t\t\t\t\tcookie: hook.cookie ?? this.validator?.cookie\n\t\t\t\t}\n\n\t\t\t\tif (hook.detail) {\n\t\t\t\t\tif (this.config.detail)\n\t\t\t\t\t\tthis.config.detail = mergeDeep(\n\t\t\t\t\t\t\tObject.assign({}, this.config.detail),\n\t\t\t\t\t\t\thook.detail\n\t\t\t\t\t\t)\n\t\t\t\t\telse this.config.detail = hook.detail\n\t\t\t\t}\n\n\t\t\t\tif (hook?.tags) {\n\t\t\t\t\tif (!this.config.detail)\n\t\t\t\t\t\tthis.config.detail = {\n\t\t\t\t\t\t\ttags: hook.tags\n\t\t\t\t\t\t}\n\t\t\t\t\telse this.config.detail.tags = hook.tags\n\t\t\t\t}\n\n\t\t\t\treturn this\n\t\t\t}\n\n\t\t\treturn this.guard({}, hook)\n\t\t}\n\n\t\tconst instance = new Elysia({\n\t\t\t...this.config,\n\t\t\tprefix: ''\n\t\t})\n\t\tinstance.singleton = { ...this.singleton }\n\t\tinstance.definitions = { ...this.definitions }\n\t\tinstance.inference = cloneInference(this.inference)\n\n\t\tconst sandbox = run(instance)\n\t\tthis.singleton = mergeDeep(this.singleton, instance.singleton) as any\n\t\tthis.definitions = mergeDeep(this.definitions, instance.definitions)\n\n\t\t// ? Inject getServer for websocket and trace (important, do not remove)\n\t\tsandbox.getServer = () => this.server\n\n\t\tif (sandbox.event.request.length)\n\t\t\tthis.event.request = [\n\t\t\t\t...(this.event.request || []),\n\t\t\t\t...(sandbox.event.request || [])\n\t\t\t]\n\n\t\tif (sandbox.event.onResponse.length)\n\t\t\tthis.event.onResponse = [\n\t\t\t\t...(this.event.onResponse || []),\n\t\t\t\t...(sandbox.event.onResponse || [])\n\t\t\t]\n\n\t\tthis.model(sandbox.definitions.type)\n\n\t\tObject.values(instance.router.history).forEach(\n\t\t\t({ method, path, handler, hooks: localHook }) => {\n\t\t\t\tthis.add(\n\t\t\t\t\tmethod,\n\t\t\t\t\tpath,\n\t\t\t\t\thandler,\n\t\t\t\t\tmergeHook(\n\t\t\t\t\t\thook as LocalHook<any, any, any, any, any>,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...((localHook || {}) as LocalHook<\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\tany\n\t\t\t\t\t\t\t>),\n\t\t\t\t\t\t\terror: !localHook.error\n\t\t\t\t\t\t\t\t? sandbox.event.error\n\t\t\t\t\t\t\t\t: Array.isArray(localHook.error)\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t...(localHook.error || {}),\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || [])\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\tlocalHook.error,\n\t\t\t\t\t\t\t\t\t\t...(sandbox.event.error || [])\n\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tallowMacro: true\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * Inline fn\n\t */\n\tuse<\n\t\tconst NewElysia extends AnyElysia,\n\t\tconst Param extends AnyElysia = this\n\t>(\n\t\tplugin: MaybePromise<(app: Param) => MaybePromise<NewElysia>>\n\t): NewElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & NewElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<Definitions & NewElysia['_types']['Definitions']>,\n\t\t\t\tPrettify2<Metadata & NewElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tPrettify2<Ephemeral & NewElysia['_ephemeral']>,\n\t\t\t\tPrettify2<Volatile & NewElysia['_volatile']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\n\t/**\n\t * Entire Instance\n\t **/\n\tuse<const NewElysia extends AnyElysia>(\n\t\tinstance: MaybePromise<NewElysia>\n\t): NewElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & NewElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<Definitions & NewElysia['_types']['Definitions']>,\n\t\t\t\tPrettify2<Metadata & NewElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tPrettify2<Volatile & NewElysia['_ephemeral']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\n\t/**\n\t * Import fn\n\t */\n\tuse<const NewElysia extends AnyElysia>(\n\t\tplugin: Promise<{\n\t\t\tdefault: (elysia: AnyElysia) => MaybePromise<NewElysia>\n\t\t}>\n\t): NewElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & NewElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<Definitions & NewElysia['_types']['Definitions']>,\n\t\t\t\tPrettify2<Metadata & NewElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tPrettify2<Ephemeral & NewElysia['_ephemeral']>,\n\t\t\t\tPrettify2<Volatile & NewElysia['_volatile']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & NewElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, NewElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\n\t/**\n\t * Import entire instance\n\t */\n\tuse<const LazyLoadElysia extends AnyElysia>(\n\t\tplugin: Promise<{\n\t\t\tdefault: LazyLoadElysia\n\t\t}>\n\t): LazyLoadElysia['_scoped'] extends false\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t// @ts-expect-error - This is truly ideal\n\t\t\t\tPrettify2<Singleton & LazyLoadElysia['_types']['Singleton']>,\n\t\t\t\tPrettify2<\n\t\t\t\t\tDefinitions & LazyLoadElysia['_types']['Definitions']\n\t\t\t\t>,\n\t\t\t\tPrettify2<Metadata & LazyLoadElysia['_types']['Metadata']>,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & LazyLoadElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, LazyLoadElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tPrettify2<Volatile & LazyLoadElysia['_ephemeral']>\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tBasePath extends ``\n\t\t\t\t\t? Routes & LazyLoadElysia['_routes']\n\t\t\t\t\t: Routes & CreateEden<BasePath, LazyLoadElysia['_routes']>,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t/**\n\t * ### use\n\t * Merge separate logic of Elysia with current\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * const plugin = (app: Elysia) => app\n\t * .get('/plugin', () => 'hi')\n\t *\n\t * new Elysia()\n\t * .use(plugin)\n\t * ```\n\t */\n\tuse(\n\t\tplugin:\n\t\t\t| MaybePromise<AnyElysia>\n\t\t\t| MaybePromise<\n\t\t\t\t\tAnyElysia | ((app: AnyElysia) => MaybePromise<AnyElysia>)\n\t\t\t >\n\t\t\t| Promise<{\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t| AnyElysia\n\t\t\t\t\t\t| ((app: AnyElysia) => MaybePromise<AnyElysia>)\n\t\t\t }>,\n\t\toptions?: { scoped?: boolean }\n\t): AnyElysia {\n\t\tif (options?.scoped)\n\t\t\treturn this.guard({}, (app) => app.use(plugin as any))\n\n\t\tif (Array.isArray(plugin)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\t\tlet current = this\n\n\t\t\tfor (const p of plugin) current = this.use(p) as any\n\n\t\t\treturn current\n\t\t}\n\n\t\tif (plugin instanceof Promise) {\n\t\t\tthis.promisedModules.add(\n\t\t\t\tplugin\n\t\t\t\t\t.then((plugin) => {\n\t\t\t\t\t\tif (typeof plugin === 'function') return plugin(this)\n\n\t\t\t\t\t\tif (plugin instanceof Elysia) return this._use(plugin)\n\n\t\t\t\t\t\tif (typeof plugin.default === 'function')\n\t\t\t\t\t\t\treturn plugin.default(this)\n\n\t\t\t\t\t\tif (plugin.default instanceof Elysia)\n\t\t\t\t\t\t\treturn this._use(plugin.default)\n\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t'Invalid plugin type. Expected Elysia instance, function, or module with \"default\" as Elysia instance or function that returns Elysia instance.'\n\t\t\t\t\t\t)\n\t\t\t\t\t})\n\t\t\t\t\t.then((x) => x.compile())\n\t\t\t)\n\t\t\treturn this\n\t\t}\n\n\t\treturn this._use(plugin)\n\t}\n\n\tprivate _use(\n\t\tplugin: AnyElysia | ((app: AnyElysia) => MaybePromise<AnyElysia>)\n\t) {\n\t\tif (typeof plugin === 'function') {\n\t\t\tconst instance = plugin(this as unknown as any) as unknown as any\n\t\t\tif (instance instanceof Promise) {\n\t\t\t\tthis.promisedModules.add(\n\t\t\t\t\tinstance\n\t\t\t\t\t\t.then((plugin) => {\n\t\t\t\t\t\t\tif (plugin instanceof Elysia) {\n\t\t\t\t\t\t\t\tthis.compile()\n\n\t\t\t\t\t\t\t\t// Recompile async plugin routes\n\t\t\t\t\t\t\t\tfor (const {\n\t\t\t\t\t\t\t\t\tmethod,\n\t\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\t\thandler,\n\t\t\t\t\t\t\t\t\thooks\n\t\t\t\t\t\t\t\t} of Object.values(plugin.router.history)) {\n\t\t\t\t\t\t\t\t\tthis.add(\n\t\t\t\t\t\t\t\t\t\tmethod,\n\t\t\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\t\t\thandler,\n\t\t\t\t\t\t\t\t\t\tmergeHook(\n\t\t\t\t\t\t\t\t\t\t\thooks as LocalHook<\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany,\n\t\t\t\t\t\t\t\t\t\t\t\tany\n\t\t\t\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\terror: plugin.event.error\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn plugin\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (typeof plugin === 'function')\n\t\t\t\t\t\t\t\treturn plugin(\n\t\t\t\t\t\t\t\t\tthis as unknown as any\n\t\t\t\t\t\t\t\t) as unknown as Elysia\n\n\t\t\t\t\t\t\tif (typeof plugin.default === 'function')\n\t\t\t\t\t\t\t\treturn plugin.default(\n\t\t\t\t\t\t\t\t\tthis as unknown as any\n\t\t\t\t\t\t\t\t) as unknown as Elysia\n\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn this._use(plugin)\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.then((x) => x.compile())\n\t\t\t\t)\n\t\t\t\treturn this as unknown as any\n\t\t\t}\n\n\t\t\treturn instance\n\t\t}\n\n\t\tif (plugin.promisedModules.size) {\n\t\t\tthis.promisedModules.add(\n\t\t\t\tplugin.modules\n\t\t\t\t\t.then(() => this._use(plugin))\n\t\t\t\t\t.then((x) => x.compile())\n\t\t\t)\n\t\t\treturn this\n\t\t}\n\n\t\tconst { name, seed } = plugin.config\n\n\t\tplugin.getServer = () => this.getServer()\n\n\t\t/**\n\t\t * Model and error is required for Swagger generation\n\t\t */\n\t\tplugin.model(this.definitions.type as any)\n\t\tplugin.error(this.definitions.error as any)\n\n\t\tconst isScoped = plugin.config.scoped as boolean\n\t\tif (isScoped) {\n\t\t\tif (name) {\n\t\t\t\tif (!(name in this.dependencies)) this.dependencies[name] = []\n\n\t\t\t\tconst current =\n\t\t\t\t\tseed !== undefined\n\t\t\t\t\t\t? checksum(name + JSON.stringify(seed))\n\t\t\t\t\t\t: 0\n\n\t\t\t\tif (\n\t\t\t\t\tthis.dependencies[name].some(\n\t\t\t\t\t\t({ checksum }) => current === checksum\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn this\n\n\t\t\t\tthis.dependencies[name].push(\n\t\t\t\t\t!this.config?.analytic\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies,\n\t\t\t\t\t\t\t\tstack: plugin.telemetry.stack,\n\t\t\t\t\t\t\t\troutes: plugin.router.history,\n\t\t\t\t\t\t\t\tdecorators: plugin.singleton.decorator,\n\t\t\t\t\t\t\t\tstore: plugin.singleton.store,\n\t\t\t\t\t\t\t\ttype: plugin.definitions.type,\n\t\t\t\t\t\t\t\terror: plugin.definitions.error,\n\t\t\t\t\t\t\t\tderive: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x.subType === 'derive')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.fn.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tresolve: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x.subType === 'derive')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.fn.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t }\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tplugin.extender.macros = this.extender.macros.concat(\n\t\t\t\tplugin.extender.macros\n\t\t\t)\n\n\t\t\tconst macroHashes = <(number | undefined)[]>[]\n\n\t\t\tfor (let i = 0; i < plugin.extender.macros.length; i++) {\n\t\t\t\tconst macro = this.extender.macros[i]\n\n\t\t\t\tif (macroHashes.includes(macro.checksum)) {\n\t\t\t\t\tplugin.extender.macros.splice(i, 1)\n\t\t\t\t\ti--\n\t\t\t\t}\n\n\t\t\t\tmacroHashes.push(macro.checksum)\n\t\t\t}\n\n\t\t\tplugin.onRequest((context) => {\n\t\t\t\tObject.assign(context, this.singleton.decorator)\n\t\t\t\tObject.assign(context.store, this.singleton.store)\n\t\t\t})\n\n\t\t\tif (plugin.event.trace.length)\n\t\t\t\tplugin.event.trace.push(...plugin.event.trace)\n\n\t\t\tif (!plugin.config.prefix)\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.\"\n\t\t\t\t)\n\n\t\t\tif (plugin.event.error.length)\n\t\t\t\tplugin.event.error.push(...this.event.error)\n\n\t\t\tif (plugin.config.aot) plugin.compile()\n\n\t\t\tif (isScoped === true && plugin.config.prefix) {\n\t\t\t\tthis.mount(plugin.config.prefix + '/', plugin.fetch)\n\n\t\t\t\t// Ensure that when using plugins routes are correctly showing up in the .routes property. Else plugins e.g. swagger will not correctly work.\n\t\t\t\t// This also avoids adding routes multiple times.\n\t\t\t\tfor (const route of plugin.router.history) {\n\t\t\t\t\tthis.routeTree.set(\n\t\t\t\t\t\troute.method + `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\tthis.router.history.length\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.router.history.push({\n\t\t\t\t\t\t...route,\n\t\t\t\t\t\tpath: `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\thooks: mergeHook(route.hooks, {\n\t\t\t\t\t\t\terror: this.event.error\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.mount(plugin.fetch)\n\n\t\t\t\tfor (const route of plugin.router.history) {\n\t\t\t\t\tthis.routeTree.set(\n\t\t\t\t\t\troute.method + `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\tthis.router.history.length\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.router.history.push({\n\t\t\t\t\t\t...route,\n\t\t\t\t\t\tpath: `${plugin.config.prefix}${route.path}`,\n\t\t\t\t\t\thooks: mergeHook(route.hooks, {\n\t\t\t\t\t\t\terror: this.event.error\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this\n\t\t} else {\n\t\t\tthis.headers(plugin.setHeaders)\n\n\t\t\tplugin.reporter = this.reporter\n\t\t\tfor (const trace of plugin.event.trace)\n\t\t\t\tif (trace.scope && trace.scope !== 'local')\n\t\t\t\t\tthis.trace(trace as any)\n\n\t\t\tif (name) {\n\t\t\t\tif (!(name in this.dependencies)) this.dependencies[name] = []\n\n\t\t\t\tconst current =\n\t\t\t\t\tseed !== undefined\n\t\t\t\t\t\t? checksum(name + JSON.stringify(seed))\n\t\t\t\t\t\t: 0\n\n\t\t\t\tif (\n\t\t\t\t\t!this.dependencies[name].some(\n\t\t\t\t\t\t({ checksum }) => current === checksum\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthis.extender.macros = this.extender.macros.concat(\n\t\t\t\t\t\tplugin.extender.macros\n\t\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.extender.macros = this.extender.macros.concat(\n\t\t\t\t\tplugin.extender.macros\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst macroHashes: number[] = []\n\n\t\t\tfor (let i = 0; i < this.extender.macros.length; i++) {\n\t\t\t\tconst macro = this.extender.macros[i]\n\n\t\t\t\tif (macro.checksum) {\n\t\t\t\t\tif (macroHashes.includes(macro.checksum)) {\n\t\t\t\t\t\tthis.extender.macros.splice(i, 1)\n\t\t\t\t\t\ti--\n\t\t\t\t\t}\n\n\t\t\t\t\tmacroHashes.push(macro.checksum)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.inference = {\n\t\t\t\tevent: {\n\t\t\t\t\tbody:\n\t\t\t\t\t\tthis.inference.event.body ||\n\t\t\t\t\t\tplugin.inference.event.body,\n\t\t\t\t\tcookie:\n\t\t\t\t\t\tthis.inference.event.cookie ||\n\t\t\t\t\t\tplugin.inference.event.cookie,\n\t\t\t\t\theaders:\n\t\t\t\t\t\tthis.inference.event.headers ||\n\t\t\t\t\t\tplugin.inference.event.headers,\n\t\t\t\t\tqueries: [\n\t\t\t\t\t\t...this.inference.event.queries,\n\t\t\t\t\t\t...plugin.inference.event.queries\n\t\t\t\t\t],\n\t\t\t\t\tquery:\n\t\t\t\t\t\tthis.inference.event.query ||\n\t\t\t\t\t\tplugin.inference.event.query,\n\t\t\t\t\tset: this.inference.event.set || plugin.inference.event.set,\n\t\t\t\t\tunknownQueries:\n\t\t\t\t\t\tthis.inference.event.unknownQueries ||\n\t\t\t\t\t\tplugin.inference.event.unknownQueries\n\t\t\t\t},\n\t\t\t\ttrace: {\n\t\t\t\t\trequest:\n\t\t\t\t\t\tthis.inference.trace.request ||\n\t\t\t\t\t\tplugin.inference.trace.request,\n\t\t\t\t\tparse:\n\t\t\t\t\t\tthis.inference.trace.parse ||\n\t\t\t\t\t\tplugin.inference.trace.parse,\n\t\t\t\t\ttransform:\n\t\t\t\t\t\tthis.inference.trace.transform ||\n\t\t\t\t\t\tplugin.inference.trace.transform,\n\t\t\t\t\thandle:\n\t\t\t\t\t\tthis.inference.trace.handle ||\n\t\t\t\t\t\tplugin.inference.trace.handle,\n\t\t\t\t\tbeforeHandle:\n\t\t\t\t\t\tthis.inference.trace.beforeHandle ||\n\t\t\t\t\t\tplugin.inference.trace.beforeHandle,\n\t\t\t\t\tafterHandle:\n\t\t\t\t\t\tthis.inference.trace.afterHandle ||\n\t\t\t\t\t\tplugin.inference.trace.afterHandle,\n\t\t\t\t\terror:\n\t\t\t\t\t\tthis.inference.trace.error ||\n\t\t\t\t\t\tplugin.inference.trace.error,\n\t\t\t\t\tcontext:\n\t\t\t\t\t\tthis.inference.trace.context ||\n\t\t\t\t\t\tplugin.inference.trace.context,\n\t\t\t\t\tstore:\n\t\t\t\t\t\tthis.inference.trace.store ||\n\t\t\t\t\t\tplugin.inference.trace.store,\n\t\t\t\t\tset: this.inference.trace.set || plugin.inference.trace.set\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.decorate(plugin.singleton.decorator)\n\t\tthis.state(plugin.singleton.store)\n\t\tthis.model(plugin.definitions.type)\n\t\tthis.error(plugin.definitions.error as any)\n\n\t\tfor (const { method, path, handler, hooks } of Object.values(\n\t\t\tplugin.router.history\n\t\t)) {\n\t\t\tthis.add(\n\t\t\t\tmethod,\n\t\t\t\tpath,\n\t\t\t\thandler,\n\t\t\t\tmergeHook(\n\t\t\t\t\thooks as LocalHook<any, any, any, any, any, any, any>,\n\t\t\t\t\t{\n\t\t\t\t\t\terror: plugin.event.error\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\n\t\tif (!isScoped)\n\t\t\tif (name) {\n\t\t\t\tif (!(name in this.dependencies)) this.dependencies[name] = []\n\n\t\t\t\tconst current =\n\t\t\t\t\tseed !== undefined\n\t\t\t\t\t\t? checksum(name + JSON.stringify(seed))\n\t\t\t\t\t\t: 0\n\n\t\t\t\tif (\n\t\t\t\t\tthis.dependencies[name].some(\n\t\t\t\t\t\t({ checksum }) => current === checksum\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn this\n\n\t\t\t\tthis.dependencies[name].push(\n\t\t\t\t\t!this.config?.analytic\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tname: plugin.config.name,\n\t\t\t\t\t\t\t\tseed: plugin.config.seed,\n\t\t\t\t\t\t\t\tchecksum: current,\n\t\t\t\t\t\t\t\tdependencies: plugin.dependencies,\n\t\t\t\t\t\t\t\tstack: plugin.telemetry.stack,\n\t\t\t\t\t\t\t\troutes: plugin.router.history,\n\t\t\t\t\t\t\t\tdecorators: plugin.singleton,\n\t\t\t\t\t\t\t\tstore: plugin.singleton.store,\n\t\t\t\t\t\t\t\ttype: plugin.definitions.type,\n\t\t\t\t\t\t\t\terror: plugin.definitions.error,\n\t\t\t\t\t\t\t\tderive: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x?.subType === 'derive')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tresolve: plugin.event.transform\n\t\t\t\t\t\t\t\t\t.filter((x) => x?.subType === 'resolve')\n\t\t\t\t\t\t\t\t\t.map((x) => ({\n\t\t\t\t\t\t\t\t\t\tfn: x.toString(),\n\t\t\t\t\t\t\t\t\t\tstack: new Error().stack ?? ''\n\t\t\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t }\n\t\t\t\t)\n\n\t\t\t\tthis.event = mergeLifeCycle(\n\t\t\t\t\tthis.event,\n\t\t\t\t\tfilterGlobalHook(plugin.event),\n\t\t\t\t\tcurrent\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.event = mergeLifeCycle(\n\t\t\t\t\tthis.event,\n\t\t\t\t\tfilterGlobalHook(plugin.event)\n\t\t\t\t)\n\t\t\t}\n\n\t\treturn this\n\t}\n\n\tmacro<const NewMacro extends BaseMacro>(\n\t\tmacro: (\n\t\t\troute: MacroManager<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Partial<Ephemeral['derive'] & Volatile['derive']>\n\t\t\t\t\tresolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>\n\t\t\t\t},\n\t\t\t\tDefinitions['error']\n\t\t\t>\n\t\t) => NewMacro\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\t{\n\t\t\tschema: Metadata['schema']\n\t\t\tmacro: Metadata['macro'] & Partial<MacroToProperty<NewMacro>>\n\t\t},\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tconst hook: MacroQueue = {\n\t\t\tchecksum: checksum(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tname: this.config.name,\n\t\t\t\t\tseed: this.config.seed,\n\t\t\t\t\tcontent: macro.toString()\n\t\t\t\t})\n\t\t\t),\n\t\t\tfn: macro as any\n\t\t}\n\n\t\tthis.extender.macros.push(hook)\n\n\t\treturn this as any\n\t}\n\n\tmount(\n\t\thandle: ((request: Request) => MaybePromise<Response>) | AnyElysia\n\t): this\n\tmount(\n\t\tpath: string,\n\t\thandle: ((request: Request) => MaybePromise<Response>) | AnyElysia\n\t): this\n\n\tmount(\n\t\tpath:\n\t\t\t| string\n\t\t\t| ((request: Request) => MaybePromise<Response>)\n\t\t\t| AnyElysia,\n\t\thandle?: ((request: Request) => MaybePromise<Response>) | AnyElysia\n\t) {\n\t\tif (\n\t\t\tpath instanceof Elysia ||\n\t\t\ttypeof path === 'function' ||\n\t\t\tpath.length === 0 ||\n\t\t\tpath === '/'\n\t\t) {\n\t\t\tconst run =\n\t\t\t\ttypeof path === 'function'\n\t\t\t\t\t? path\n\t\t\t\t\t: path instanceof Elysia\n\t\t\t\t\t? path.compile().fetch\n\t\t\t\t\t: handle instanceof Elysia\n\t\t\t\t\t? handle.compile().fetch\n\t\t\t\t\t: handle!\n\n\t\t\tconst handler: Handler<any, any> = async ({ request, path }) =>\n\t\t\t\trun(\n\t\t\t\t\tnew Request(\n\t\t\t\t\t\treplaceUrlPath(request.url, path || '/'),\n\t\t\t\t\t\trequest\n\t\t\t\t\t)\n\t\t\t\t)\n\n\t\t\tthis.all(\n\t\t\t\t'/*',\n\t\t\t\thandler as any,\n\t\t\t\t{\n\t\t\t\t\ttype: 'none'\n\t\t\t\t} as any\n\t\t\t)\n\n\t\t\treturn this\n\t\t}\n\n\t\tconst length = path.length\n\n\t\tif (handle instanceof Elysia) handle = handle.compile().fetch\n\n\t\tconst handler: Handler<any, any> = async ({ request, path }) =>\n\t\t\t(handle as Function)!(\n\t\t\t\tnew Request(\n\t\t\t\t\treplaceUrlPath(request.url, path.slice(length) || '/'),\n\t\t\t\t\trequest\n\t\t\t\t)\n\t\t\t)\n\n\t\tthis.all(\n\t\t\tpath,\n\t\t\thandler as any,\n\t\t\t{\n\t\t\t\ttype: 'none'\n\t\t\t} as any\n\t\t)\n\n\t\tthis.all(\n\t\t\tpath + (path.endsWith('/') ? '*' : '/*'),\n\t\t\thandler as any,\n\t\t\t{\n\t\t\t\ttype: 'none'\n\t\t\t} as any\n\t\t)\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### get\n\t * Register handler for path with method [GET]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .get('/', () => 'hi')\n\t * .get('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tget<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tget: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('GET', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### post\n\t * Register handler for path with method [POST]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .post('/', () => 'hi')\n\t * .post('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tpost<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tpost: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('POST', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### put\n\t * Register handler for path with method [PUT]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .put('/', () => 'hi')\n\t * .put('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tput<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tput: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('PUT', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### patch\n\t * Register handler for path with method [PATCH]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .patch('/', () => 'hi')\n\t * .patch('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tpatch<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tpatch: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('PATCH', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### delete\n\t * Register handler for path with method [DELETE]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .delete('/', () => 'hi')\n\t * .delete('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tdelete<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tdelete: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('DELETE', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### options\n\t * Register handler for path with method [POST]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .options('/', () => 'hi')\n\t * .options('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\toptions<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('OPTIONS', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### all\n\t * Register handler for path with method [ALL]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .all('/', () => 'hi')\n\t * .all('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tall<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\t[method in string]: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('ALL', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### head\n\t * Register handler for path with method [HEAD]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .head('/', () => 'hi')\n\t * .head('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\thead<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\thead: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('HEAD', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### connect\n\t * Register handler for path with method [CONNECT]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .connect('/', () => 'hi')\n\t * .connect('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\tconnect<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tconnect: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add('CONNECT', path, handler as any, hook)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### route\n\t * Register handler for path with method [ROUTE]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .route('/', () => 'hi')\n\t * .route('/with-hook', () => 'hi', {\n\t * response: t.String()\n\t * })\n\t * ```\n\t */\n\troute<\n\t\tconst Method extends HTTPMethod,\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema']\n\t\t>,\n\t\tconst Handle extends InlineHandler<\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t>(\n\t\tmethod: Method,\n\t\tpath: Path,\n\t\thandler: Handle,\n\t\thook?: LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t> & {\n\t\t\tconfig: {\n\t\t\t\tallowMeta?: boolean\n\t\t\t}\n\t\t}\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath & string}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\t[method in Method]: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: ComposeElysiaResponse<\n\t\t\t\t\t\t\tSchema['response'],\n\t\t\t\t\t\t\tHandle\n\t\t\t\t\t\t>\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tthis.add(method.toUpperCase(), path, handler as any, hook, hook?.config)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### ws\n\t * Register handler for path with method [ws]\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * import { Elysia, t } from 'elysia'\n\t *\n\t * new Elysia()\n\t * .ws('/', {\n\t * message(ws, message) {\n\t * ws.send(message)\n\t * }\n\t * })\n\t * ```\n\t */\n\tws<\n\t\tconst Path extends string,\n\t\tconst LocalSchema extends InputSchema<\n\t\t\tkeyof Definitions['type'] & string\n\t\t>,\n\t\tconst Schema extends MergeSchema<\n\t\t\tUnwrapRoute<LocalSchema, Definitions['type']>,\n\t\t\tMetadata['schema']\n\t\t>\n\t>(\n\t\tpath: Path,\n\t\toptions: WS.LocalHook<\n\t\t\tLocalSchema,\n\t\t\tSchema,\n\t\t\tSingleton & {\n\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t},\n\t\t\tDefinitions['error'],\n\t\t\tMetadata['macro'],\n\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`\n\t\t>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes &\n\t\t\tCreateEden<\n\t\t\t\t`${BasePath}${Path extends '/' ? '/index' : Path}`,\n\t\t\t\t{\n\t\t\t\t\tsubscribe: {\n\t\t\t\t\t\tbody: Schema['body']\n\t\t\t\t\t\tparams: undefined extends Schema['params']\n\t\t\t\t\t\t\t? Record<GetPathParameter<Path>, string>\n\t\t\t\t\t\t\t: Schema['params']\n\t\t\t\t\t\tquery: Schema['query']\n\t\t\t\t\t\theaders: Schema['headers']\n\t\t\t\t\t\tresponse: Schema['response']\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tconst transform = options.transformMessage\n\t\t\t? Array.isArray(options.transformMessage)\n\t\t\t\t? options.transformMessage\n\t\t\t\t: [options.transformMessage]\n\t\t\t: undefined\n\n\t\tlet server: Server | null = null\n\n\t\tconst validateMessage = getSchemaValidator(options?.body, {\n\t\t\tmodels: this.definitions.type as Record<string, TSchema>,\n\t\t\tnormalize: this.config.normalize\n\t\t})\n\n\t\tconst validateResponse = getSchemaValidator(options?.response as any, {\n\t\t\tmodels: this.definitions.type as Record<string, TSchema>,\n\t\t\tnormalize: this.config.normalize\n\t\t})\n\n\t\tconst parseMessage = (message: any) => {\n\t\t\tif (typeof message === 'string') {\n\t\t\t\tconst start = message?.charCodeAt(0)\n\n\t\t\t\tif (start === 47 || start === 123)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tmessage = JSON.parse(message)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Not empty\n\t\t\t\t\t}\n\t\t\t\telse if (isNumericString(message)) message = +message\n\t\t\t}\n\n\t\t\tif (transform?.length)\n\t\t\t\tfor (let i = 0; i < transform.length; i++) {\n\t\t\t\t\tconst temp = transform[i](message)\n\n\t\t\t\t\tif (temp !== undefined) message = temp\n\t\t\t\t}\n\n\t\t\treturn message\n\t\t}\n\n\t\tthis.route(\n\t\t\t'$INTERNALWS',\n\t\t\tpath as any,\n\t\t\t// @ts-expect-error\n\t\t\t(context) => {\n\t\t\t\t// ! Enable static code analysis just in case resolveUnknownFunction doesn't work, do not remove\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\t\tconst { set, path, qi, headers, query, params } = context\n\n\t\t\t\tif (server === null) server = this.getServer()\n\n\t\t\t\tif (\n\t\t\t\t\tserver?.upgrade<any>(context.request, {\n\t\t\t\t\t\theaders: (typeof options.upgrade === 'function'\n\t\t\t\t\t\t\t? options.upgrade(context as any as Context)\n\t\t\t\t\t\t\t: options.upgrade) as Bun.HeadersInit,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tvalidator: validateResponse,\n\t\t\t\t\t\t\topen(ws: ServerWebSocket<any>) {\n\t\t\t\t\t\t\t\toptions.open?.(new ElysiaWS(ws, context as any))\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmessage: (ws: ServerWebSocket<any>, msg: any) => {\n\t\t\t\t\t\t\t\tconst message = parseMessage(msg)\n\n\t\t\t\t\t\t\t\tif (validateMessage?.Check(message) === false)\n\t\t\t\t\t\t\t\t\treturn void ws.send(\n\t\t\t\t\t\t\t\t\t\tnew ValidationError(\n\t\t\t\t\t\t\t\t\t\t\t'message',\n\t\t\t\t\t\t\t\t\t\t\tvalidateMessage,\n\t\t\t\t\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t\t\t\t\t).message as string\n\t\t\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\t\toptions.message?.(\n\t\t\t\t\t\t\t\t\tnew ElysiaWS(ws, context as any),\n\t\t\t\t\t\t\t\t\tmessage as any\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdrain(ws: ServerWebSocket<any>) {\n\t\t\t\t\t\t\t\toptions.drain?.(\n\t\t\t\t\t\t\t\t\tnew ElysiaWS(ws, context as any)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tclose(\n\t\t\t\t\t\t\t\tws: ServerWebSocket<any>,\n\t\t\t\t\t\t\t\tcode: number,\n\t\t\t\t\t\t\t\treason: string\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\toptions.close?.(\n\t\t\t\t\t\t\t\t\tnew ElysiaWS(ws, context as any),\n\t\t\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\t\t\treason\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t\t\treturn\n\n\t\t\t\tset.status = 400\n\n\t\t\t\treturn 'Expected a websocket connection'\n\t\t\t},\n\t\t\t{\n\t\t\t\tbeforeHandle: options.beforeHandle,\n\t\t\t\ttransform: options.transform,\n\t\t\t\theaders: options.headers,\n\t\t\t\tparams: options.params,\n\t\t\t\tquery: options.query\n\t\t\t} as any\n\t\t)\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### state\n\t * Assign global mutatable state accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .state({ counter: 0 })\n\t * .get('/', (({ counter }) => ++counter)\n\t * ```\n\t */\n\tstate<const Name extends string | number | symbol, Value>(\n\t\tname: Name,\n\t\tvalue: Value\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Singleton['decorator']\n\t\t\tstore: Prettify<\n\t\t\t\tSingleton['store'] & {\n\t\t\t\t\t[name in Name]: Value\n\t\t\t\t}\n\t\t\t>\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### state\n\t * Assign global mutatable state accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .state('counter', 0)\n\t * .get('/', (({ counter }) => ++counter)\n\t * ```\n\t */\n\tstate<Store extends Record<string, unknown>>(\n\t\tstore: Store\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Singleton['decorator']\n\t\t\tstore: Prettify<Singleton['store'] & Store>\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tstate<NewStore extends Record<string, unknown>>(\n\t\tmapper: (decorators: Singleton['store']) => NewStore\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Singleton['decorator']\n\t\t\tstore: NewStore\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### state\n\t * Assign global mutatable state accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .state('counter', 0)\n\t * .get('/', (({ counter }) => ++counter)\n\t * ```\n\t */\n\tstate(\n\t\tname: string | number | symbol | Record<string, unknown> | Function,\n\t\tvalue?: unknown\n\t) {\n\t\tswitch (typeof name) {\n\t\t\tcase 'object':\n\t\t\t\tthis.singleton.store = mergeDeep(this.singleton.store, name)\n\n\t\t\t\treturn this as any\n\n\t\t\tcase 'function':\n\t\t\t\tthis.singleton.store = name(this.singleton.store)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\tif (!(name in this.singleton.store)) {\n\t\t\t// eslint-disable-next-line no-extra-semi\n\t\t\t;(\n\t\t\t\tthis.singleton.store as Record<\n\t\t\t\t\tstring | number | symbol,\n\t\t\t\t\tunknown\n\t\t\t\t>\n\t\t\t)[name] = value\n\t\t}\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * ### decorate\n\t * Define custom method to `Context` accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .decorate('getDate', () => Date.now())\n\t * .get('/', (({ getDate }) => getDate())\n\t * ```\n\t */\n\tdecorate<const Name extends string, const Value>(\n\t\tname: Name,\n\t\tvalue: Value\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Prettify<\n\t\t\t\tSingleton['decorator'] & {\n\t\t\t\t\t[name in Name]: Value\n\t\t\t\t}\n\t\t\t>\n\t\t\tstore: Singleton['store']\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### decorate\n\t * Define custom method to `Context` accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .decorate('getDate', () => Date.now())\n\t * .get('/', (({ getDate }) => getDate())\n\t * ```\n\t */\n\tdecorate<const NewDecorators extends Record<string, unknown>>(\n\t\tdecorators: NewDecorators\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Prettify<Singleton['decorator'] & NewDecorators>\n\t\t\tstore: Singleton['store']\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tdecorate<const NewDecorators extends Record<string, unknown>>(\n\t\tmapper: (decorators: Singleton['decorator']) => NewDecorators\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: NewDecorators\n\t\t\tstore: Singleton['store']\n\t\t\tderive: Singleton['derive']\n\t\t\tresolve: Singleton['resolve']\n\t\t},\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\t/**\n\t * ### decorate\n\t * Define custom method to `Context` accessible for all handler\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .decorate('getDate', () => Date.now())\n\t * .get('/', (({ getDate }) => getDate())\n\t * ```\n\t */\n\tdecorate(\n\t\tname: string | Record<string, unknown> | Function,\n\t\tvalue?: unknown\n\t) {\n\t\tswitch (typeof name) {\n\t\t\tcase 'object':\n\t\t\t\tthis.singleton.decorator = mergeDeep(\n\t\t\t\t\tthis.singleton.decorator,\n\t\t\t\t\tname\n\t\t\t\t)\n\n\t\t\t\treturn this as any\n\n\t\t\tcase 'function':\n\t\t\t\tthis.singleton.decorator = name(this.singleton.decorator)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\tif (!(name in this.singleton.decorator))\n\t\t\tthis.singleton.decorator[name] = value\n\n\t\treturn this as any\n\t}\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tderive<const Derivative extends Record<string, unknown>>(\n\t\ttransform: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton & {\n\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Derivative>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: Prettify<\n\t\t\t\tVolatile['derive'] &\n\t\t\t\t\t// Exclude `return error`\n\t\t\t\t\tExcludeElysiaResponse<Derivative>\n\t\t\t>\n\t\t\tresolve: Volatile['resolve']\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\t/**\n\t * Derive new property for each request with access to `Context`.\n\t *\n\t * If error is thrown, the scope will skip to handling error instead.\n\t *\n\t * ---\n\t * @example\n\t * new Elysia()\n\t * .state('counter', 1)\n\t * .derive(({ store }) => ({\n\t * increase() {\n\t * store.counter++\n\t * }\n\t * }))\n\t */\n\tderive<\n\t\tconst Derivative extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\ttransform: (\n\t\t\tcontext: Prettify<\n\t\t\t\tContext<\n\t\t\t\t\tMetadata['schema'] &\n\t\t\t\t\t\tEphemeral['schema'] &\n\t\t\t\t\t\tVolatile['schema'],\n\t\t\t\t\tSingleton &\n\t\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['derive']\n\t\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t\t }),\n\t\t\t\t\tBasePath\n\t\t\t\t>\n\t\t\t>\n\t\t) => MaybePromise<Derivative>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tSingleton['resolve'] & ExcludeElysiaResponse<Derivative>\n\t\t\t\t\t>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] & ExcludeElysiaResponse<Derivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] & ExcludeElysiaResponse<Derivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\tderive(\n\t\toptionsOrTransform: { as?: LifeCycleType } | Function,\n\t\ttransform?: Function\n\t) {\n\t\tif (!transform) {\n\t\t\ttransform = optionsOrTransform as any\n\t\t\toptionsOrTransform = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'derive',\n\t\t\tfn: transform!\n\t\t}\n\n\t\treturn this.onTransform(optionsOrTransform as any, hook as any) as any\n\t}\n\n\tmodel<const Name extends string, const Model extends TSchema>(\n\t\tname: Name,\n\t\tmodel: Model\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Prettify<\n\t\t\t\tDefinitions['type'] & { [name in Name]: Static<Model> }\n\t\t\t>\n\t\t\terror: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tmodel<const Recorder extends Record<string, TSchema>>(\n\t\trecord: Recorder\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: Prettify<\n\t\t\t\tDefinitions['type'] & {\n\t\t\t\t\t[key in keyof Recorder]: Static<Recorder[key]>\n\t\t\t\t}\n\t\t\t>\n\t\t\terror: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tmodel<const NewType extends Record<string, TSchema>>(\n\t\tmapper: (decorators: {\n\t\t\t[type in keyof Definitions['type']]: ReturnType<\n\t\t\t\ttypeof t.Unsafe<Definitions['type'][type]>\n\t\t\t>\n\t\t}) => NewType\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\t{\n\t\t\ttype: { [x in keyof NewType]: Static<NewType[x]> }\n\t\t\terror: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t>\n\n\tmodel(name: string | Record<string, TSchema> | Function, model?: TSchema) {\n\t\tswitch (typeof name) {\n\t\t\tcase 'object':\n\t\t\t\tObject.entries(name).forEach(([key, value]) => {\n\t\t\t\t\tif (!(key in this.definitions.type))\n\t\t\t\t\t\tthis.definitions.type[key] = value as TSchema\n\t\t\t\t})\n\n\t\t\t\treturn this\n\n\t\t\tcase 'function':\n\t\t\t\tthis.definitions.type = name(this.definitions.type)\n\n\t\t\t\treturn this as any\n\t\t}\n\n\t\t;(this.definitions.type as Record<string, TSchema>)[name] = model!\n\n\t\treturn this as any\n\t}\n\n\tmapDerive<const NewDerivative extends Record<string, unknown>>(\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t) => MaybePromise<NewDerivative>\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\tSingleton,\n\t\tDefinitions,\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\t{\n\t\t\tderive: NewDerivative\n\t\t\tresolve: Volatile['resolve']\n\t\t\tschema: Volatile['schema']\n\t\t}\n\t>\n\n\tmapDerive<\n\t\tconst NewDerivative extends Record<string, unknown>,\n\t\tconst Type extends LifeCycleType\n\t>(\n\t\toptions: { as?: Type },\n\t\tmapper: (\n\t\t\tcontext: Context<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton &\n\t\t\t\t\t('global' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tresolve: Partial<\n\t\t\t\t\t\t\t\t\tEphemeral['resolve'] & Volatile['resolve']\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: 'scoped' extends Type\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['derive']>\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tPartial<Volatile['resolve']>\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\t\t\t\tresolve: Ephemeral['resolve'] &\n\t\t\t\t\t\t\t\t\tVolatile['resolve']\n\t\t\t\t\t\t }),\n\t\t\t\tBasePath\n\t\t\t>\n\t\t) => MaybePromise<NewDerivative>\n\t): Type extends 'global'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\t{\n\t\t\t\t\tdecorator: Singleton['decorator']\n\t\t\t\t\tstore: Singleton['store']\n\t\t\t\t\tderive: Singleton['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tSingleton['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewDerivative>\n\t\t\t\t\t>\n\t\t\t\t},\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\tVolatile\n\t\t >\n\t\t: Type extends 'scoped'\n\t\t? Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\t{\n\t\t\t\t\tderive: Ephemeral['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tEphemeral['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewDerivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Ephemeral['schema']\n\t\t\t\t},\n\t\t\t\tVolatile\n\t\t >\n\t\t: Elysia<\n\t\t\t\tBasePath,\n\t\t\t\tScoped,\n\t\t\t\tSingleton,\n\t\t\t\tDefinitions,\n\t\t\t\tMetadata,\n\t\t\t\tRoutes,\n\t\t\t\tEphemeral,\n\t\t\t\t{\n\t\t\t\t\tderive: Volatile['resolve']\n\t\t\t\t\tresolve: Prettify<\n\t\t\t\t\t\tVolatile['resolve'] &\n\t\t\t\t\t\t\tExcludeElysiaResponse<NewDerivative>\n\t\t\t\t\t>\n\t\t\t\t\tschema: Volatile['schema']\n\t\t\t\t}\n\t\t >\n\n\tmapDerive(\n\t\toptionsOrDerive: { as?: LifeCycleType } | Function,\n\t\tmapper?: Function\n\t) {\n\t\tif (!mapper) {\n\t\t\tmapper = optionsOrDerive as any\n\t\t\toptionsOrDerive = { as: 'local' }\n\t\t}\n\n\t\tconst hook: HookContainer = {\n\t\t\tsubType: 'derive',\n\t\t\tfn: mapper!\n\t\t}\n\n\t\treturn this.onTransform(optionsOrDerive as any, hook as any) as any\n\t}\n\n\taffix<\n\t\tconst Base extends 'prefix' | 'suffix',\n\t\tconst Type extends 'all' | 'decorator' | 'state' | 'model' | 'error',\n\t\tconst Word extends string\n\t>(\n\t\tbase: Base,\n\t\ttype: Type,\n\t\tword: Word\n\t): Elysia<\n\t\tBasePath,\n\t\tScoped,\n\t\t{\n\t\t\tdecorator: Type extends 'decorator' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['decorator']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['decorator']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Singleton['decorator']>\n\t\t\t\t: Singleton['decorator']\n\t\t\tstore: Type extends 'state' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['store']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['store']>\n\t\t\t\t\t: AddSuffix<Word, Singleton['store']>\n\t\t\t\t: Singleton['store']\n\t\t\tderive: Type extends 'decorator' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['derive']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['derive']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Singleton['derive']>\n\t\t\t\t: Singleton['derive']\n\t\t\tresolve: Type extends 'decorator' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Singleton['resolve']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Singleton['resolve']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Singleton['resolve']>\n\t\t\t\t: Singleton['resolve']\n\t\t},\n\t\t{\n\t\t\ttype: Type extends 'model' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Definitions['type']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Definitions['type']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Definitions['type']>\n\t\t\t\t: Definitions['type']\n\t\t\terror: Type extends 'error' | 'all'\n\t\t\t\t? 'prefix' extends Base\n\t\t\t\t\t? Word extends `${string}${'_' | '-' | ' '}`\n\t\t\t\t\t\t? AddPrefix<Word, Definitions['error']>\n\t\t\t\t\t\t: AddPrefixCapitalize<Word, Definitions['error']>\n\t\t\t\t\t: AddSuffixCapitalize<Word, Definitions['error']>\n\t\t\t\t: Definitions['error']\n\t\t},\n\t\tMetadata,\n\t\tRoutes,\n\t\tEphemeral,\n\t\tVolatile\n\t> {\n\t\tif (word === '') return this as any\n\n\t\tconst delimieter = ['_', '-', ' ']\n\t\tconst capitalize = (word: string) =>\n\t\t\tword[0].toUpperCase() + word.slice(1)\n\n\t\tconst joinKey =\n\t\t\tbase === 'prefix'\n\t\t\t\t? (prefix: string, word: string) =>\n\t\t\t\t\t\tdelimieter.includes(prefix.at(-1) ?? '')\n\t\t\t\t\t\t\t? prefix + word\n\t\t\t\t\t\t\t: prefix + capitalize(word)\n\t\t\t\t: delimieter.includes(word.at(-1) ?? '')\n\t\t\t\t? (suffix: string, word: string) => word + suffix\n\t\t\t\t: (suffix: string, word: string) => word + capitalize(suffix)\n\n\t\tconst remap = (type: 'decorator' | 'state' | 'model' | 'error') => {\n\t\t\tconst store: Record<string, any> = {}\n\n\t\t\tswitch (type) {\n\t\t\t\tcase 'decorator':\n\t\t\t\t\tfor (const key in this.singleton.decorator) {\n\t\t\t\t\t\tstore[joinKey(word, key)] =\n\t\t\t\t\t\t\tthis.singleton.decorator[key]\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.singleton.decorator = store\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'state':\n\t\t\t\t\tfor (const key in this.singleton.store)\n\t\t\t\t\t\tstore[joinKey(word, key)] = this.singleton.store[key]\n\n\t\t\t\t\tthis.singleton.store = store\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'model':\n\t\t\t\t\tfor (const key in this.definitions.type)\n\t\t\t\t\t\tstore[joinKey(word, key)] = this.definitions.type[key]\n\n\t\t\t\t\tthis.definitions.type = store\n\t\t\t\t\tbreak\n\n\t\t\t\tcase 'error':\n\t\t\t\t\tfor (const key in this.definitions.error)\n\t\t\t\t\t\tstore[joinKey(word, key)] = this.definitions.error[key]\n\n\t\t\t\t\tthis.definitions.error = store\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst types = Array.isArray(type) ? type : [type]\n\n\t\tfor (const type of types.some((x) => x === 'all')\n\t\t\t? ['decorator', 'state', 'model', 'error']\n\t\t\t: types)\n\t\t\tremap(type as 'decorator')\n\n\t\treturn this as any\n\t}\n\n\tprefix<\n\t\tconst Type extends 'all' | 'decorator' | 'state' | 'model' | 'error',\n\t\tconst Word extends string\n\t>(type: Type, word: Word) {\n\t\treturn this.affix('prefix', type, word)\n\t}\n\n\tsuffix<\n\t\tconst Type extends 'all' | 'decorator' | 'state' | 'model' | 'error',\n\t\tconst Word extends string\n\t>(type: Type, word: Word) {\n\t\treturn this.affix('suffix', type, word)\n\t}\n\n\tcompile() {\n\t\tthis.fetch = this.config.aot\n\t\t\t? composeGeneralHandler(this)\n\t\t\t: createDynamicHandler(this)\n\n\t\tif (typeof this.server?.reload === 'function')\n\t\t\tthis.server.reload({\n\t\t\t\t...(this.server || {}),\n\t\t\t\tfetch: this.fetch\n\t\t\t})\n\n\t\treturn this\n\t}\n\n\thandle = async (request: Request) => this.fetch(request)\n\n\t/**\n\t * Use handle can be either sync or async to save performance.\n\t *\n\t * Beside benchmark purpose, please use 'handle' instead.\n\t */\n\tfetch = (request: Request): MaybePromise<Response> => {\n\t\tif (process.env.NODE_ENV === 'production' && this.config.aot !== false)\n\t\t\tconsole.warn(\n\t\t\t\t\"Performance degradation found. Please call Elysia.compile() before using 'fetch'\"\n\t\t\t)\n\n\t\treturn (this.fetch = this.config.aot\n\t\t\t? composeGeneralHandler(this)\n\t\t\t: createDynamicHandler(this))(request)\n\t}\n\n\tprivate handleError = async (\n\t\tcontext: Partial<\n\t\t\tContext<\n\t\t\t\tMetadata['schema'] & Ephemeral['schema'] & Volatile['schema'],\n\t\t\t\tSingleton & {\n\t\t\t\t\tderive: Ephemeral['derive'] & Volatile['derive']\n\t\t\t\t\tresolve: Ephemeral['resolve'] & Volatile['resolve']\n\t\t\t\t},\n\t\t\t\tBasePath\n\t\t\t>\n\t\t> & {\n\t\t\trequest: Request\n\t\t},\n\t\terror:\n\t\t\t| Error\n\t\t\t| ValidationError\n\t\t\t| ParseError\n\t\t\t| NotFoundError\n\t\t\t| InternalServerError\n\t) =>\n\t\t(this.handleError = this.config.aot\n\t\t\t? composeErrorHandler(this)\n\t\t\t: createDynamicErrorHandler(this))(context, error)\n\n\tprivate outerErrorHandler = (error: Error) =>\n\t\tnew Response(error.message || error.name || 'Error', {\n\t\t\t// @ts-ignore\n\t\t\tstatus: error?.status ?? 500\n\t\t})\n\n\t/**\n\t * ### listen\n\t * Assign current instance to port and start serving\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * new Elysia()\n\t * .get(\"/\", () => 'hi')\n\t * .listen(3000)\n\t * ```\n\t */\n\tlisten = (\n\t\toptions: string | number | Partial<Serve>,\n\t\tcallback?: ListenCallback\n\t) => {\n\t\tif (typeof Bun === 'undefined')\n\t\t\tthrow new Error(\n\t\t\t\t'.listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch'\n\t\t\t)\n\n\t\tthis.compile()\n\n\t\tif (typeof options === 'string') {\n\t\t\tif (!isNumericString(options))\n\t\t\t\tthrow new Error('Port must be a numeric value')\n\n\t\t\toptions = parseInt(options)\n\t\t}\n\n\t\tconst fetch = this.fetch\n\n\t\tconst serve =\n\t\t\ttypeof options === 'object'\n\t\t\t\t? ({\n\t\t\t\t\t\tdevelopment: !isProduction,\n\t\t\t\t\t\treusePort: true,\n\t\t\t\t\t\t...(this.config.serve || {}),\n\t\t\t\t\t\t...(options || {}),\n\t\t\t\t\t\twebsocket: {\n\t\t\t\t\t\t\t...(this.config.websocket || {}),\n\t\t\t\t\t\t\t...(websocket || {})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tfetch,\n\t\t\t\t\t\terror: this.outerErrorHandler\n\t\t\t\t } as Serve)\n\t\t\t\t: ({\n\t\t\t\t\t\tdevelopment: !isProduction,\n\t\t\t\t\t\treusePort: true,\n\t\t\t\t\t\t...(this.config.serve || {}),\n\t\t\t\t\t\twebsocket: {\n\t\t\t\t\t\t\t...(this.config.websocket || {}),\n\t\t\t\t\t\t\t...(websocket || {})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tport: options,\n\t\t\t\t\t\tfetch,\n\t\t\t\t\t\terror: this.outerErrorHandler\n\t\t\t\t } as Serve)\n\n\t\tthis.server = Bun?.serve(serve)\n\n\t\tfor (let i = 0; i < this.event.start.length; i++)\n\t\t\tthis.event.start[i].fn(this)\n\n\t\tif (callback) callback(this.server!)\n\n\t\tprocess.on('beforeExit', () => {\n\t\t\tif (this.server) {\n\t\t\t\tthis.server.stop()\n\t\t\t\tthis.server = null\n\n\t\t\t\tfor (let i = 0; i < this.event.stop.length; i++)\n\t\t\t\t\tthis.event.stop[i].fn(this)\n\t\t\t}\n\t\t})\n\n\t\tthis.promisedModules.then(() => {\n\t\t\tBun?.gc(false)\n\t\t})\n\n\t\treturn this\n\t}\n\n\t/**\n\t * ### stop\n\t * Stop server from serving\n\t *\n\t * ---\n\t * @example\n\t * ```typescript\n\t * const app = new Elysia()\n\t * .get(\"/\", () => 'hi')\n\t * .listen(3000)\n\t *\n\t * // Sometime later\n\t * app.stop()\n\t * ```\n\t */\n\tstop = async () => {\n\t\tif (!this.server)\n\t\t\tthrow new Error(\n\t\t\t\t\"Elysia isn't running. Call `app.listen` to start the server.\"\n\t\t\t)\n\n\t\tif (this.server) {\n\t\t\tthis.server.stop()\n\t\t\tthis.server = null\n\n\t\t\tif (this.event.stop.length)\n\t\t\t\tfor (let i = 0; i < this.event.stop.length; i++)\n\t\t\t\t\tthis.event.stop[i].fn(this)\n\t\t}\n\t}\n\n\t/**\n\t * Wait until all lazy loaded modules all load is fully\n\t */\n\tget modules() {\n\t\treturn Promise.all(this.promisedModules.promises)\n\t}\n}\n\nexport { Elysia }\n\nexport { mapResponse, mapCompactResponse, mapEarlyResponse } from './handler'\nexport { t } from './type-system'\nexport { Cookie, type CookieOptions } from './cookies'\n\nexport {\n\tgetSchemaValidator,\n\tmergeHook,\n\tmergeObjectArray,\n\tgetResponseSchemaValidator,\n\tStatusMap,\n\tInvertedStatusMap\n} from './utils'\n\nexport {\n\terror,\n\tParseError,\n\tNotFoundError,\n\tValidationError,\n\tInternalServerError,\n\tInvalidCookieSignature,\n\tERROR_CODE,\n\tELYSIA_RESPONSE\n} from './error'\n\nexport type { Context, PreContext } from './context'\n\nexport type {\n\tEphemeralType,\n\tCreateEden,\n\tComposeElysiaResponse,\n\tElysiaConfig,\n\tSingletonBase,\n\tDefinitionBase,\n\tRouteBase,\n\tHandler,\n\tComposedHandler,\n\tInputSchema,\n\tLocalHook,\n\tMergeSchema,\n\tRouteSchema,\n\tUnwrapRoute,\n\tInternalRoute,\n\tHTTPMethod,\n\tSchemaValidator,\n\tVoidHandler,\n\tPreHandler,\n\tBodyHandler,\n\tOptionalHandler,\n\tErrorHandler,\n\tAfterHandler,\n\tLifeCycleEvent,\n\tTraceEvent,\n\tLifeCycleStore,\n\tLifeCycleType,\n\tMaybePromise,\n\tListenCallback,\n\tUnwrapSchema,\n\tTraceHandler,\n\tTraceProcess,\n\tTraceReporter,\n\tTraceStream,\n\tChecksum,\n\tDocumentDecoration,\n\tInferContext,\n\tInferHandler\n} from './types'\n\nexport type { Static, TSchema } from '@sinclair/typebox'\n"
33
33
  ],
34
34
  "mappings": ";AA/////fAYA,IAAS,WAAM,EAAG,GA4BT,WAAE,CAAC,EAAI,EAAS,EAAM,CAC7B,KAAK,GAAK,EACV,KAAK,QAAU,EACf,KAAK,KAAO,GAAQ,IAcb,WAAW,CAAC,EAAS,EAAO,EAAI,EAAS,EAAM,CACtD,UAAW,IAAO,WAChB,MAAM,IAAI,UAAU,iCAAiC,EAGvD,IAAI,EAAW,IAAI,GAAG,EAAI,GAAW,EAAS,CAAI,EAC9C,EAAM,EAAS,EAAS,EAAQ,EAEpC,IAAK,EAAQ,QAAQ,GAAM,EAAQ,QAAQ,GAAO,EAAU,EAAQ,wBAC1D,EA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