UNPKG

@intlify/h3

Version:
1 lines 123 kB
{"version":3,"file":"index.mjs","names":["#body","#init","#response","#headers","HTTPError","EmptyObject","#init","#headers","FastResponse","onRequest","onResponse","intlify","staticLocaleDetector: LocaleDetector | null","getHeaderLocale","translate","_translate"],"sources":["../../../node_modules/.pnpm/rou3@0.7.10/node_modules/rou3/dist/index.mjs","../../../node_modules/.pnpm/srvx@0.9.6/node_modules/srvx/dist/_chunks/_inherit-D99WuBbX.mjs","../../../node_modules/.pnpm/srvx@0.9.6/node_modules/srvx/dist/_chunks/call-BLKVUMn3.mjs","../../../node_modules/.pnpm/h3@2.0.1-rc.5/node_modules/h3/dist/h3.mjs","../src/symbols.ts","../src/index.ts"],"sourcesContent":["const NullProtoObj = /* @__PURE__ */ (() => {\n\tconst e = function() {};\n\treturn e.prototype = Object.create(null), Object.freeze(e.prototype), e;\n})();\n\n/**\n* Create a new router context.\n*/\nfunction createRouter() {\n\treturn {\n\t\troot: { key: \"\" },\n\t\tstatic: new NullProtoObj()\n\t};\n}\n\nfunction splitPath(path) {\n\tconst [_, ...s] = path.split(\"/\");\n\treturn s[s.length - 1] === \"\" ? s.slice(0, -1) : s;\n}\nfunction getMatchParams(segments, paramsMap) {\n\tconst params = new NullProtoObj();\n\tfor (const [index, name] of paramsMap) {\n\t\tconst segment = index < 0 ? segments.slice(-1 * index).join(\"/\") : segments[index];\n\t\tif (typeof name === \"string\") params[name] = segment;\n\t\telse {\n\t\t\tconst match = segment.match(name);\n\t\t\tif (match) for (const key in match.groups) params[key] = match.groups[key];\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Add a route to the router context.\n*/\nfunction addRoute(ctx, method = \"\", path, data) {\n\tmethod = method.toUpperCase();\n\tif (path.charCodeAt(0) !== 47) path = `/${path}`;\n\tconst segments = splitPath(path);\n\tlet node = ctx.root;\n\tlet _unnamedParamIndex = 0;\n\tconst paramsMap = [];\n\tconst paramsRegexp = [];\n\tfor (let i = 0; i < segments.length; i++) {\n\t\tconst segment = segments[i];\n\t\tif (segment.startsWith(\"**\")) {\n\t\t\tif (!node.wildcard) node.wildcard = { key: \"**\" };\n\t\t\tnode = node.wildcard;\n\t\t\tparamsMap.push([\n\t\t\t\t-i,\n\t\t\t\tsegment.split(\":\")[1] || \"_\",\n\t\t\t\tsegment.length === 2\n\t\t\t]);\n\t\t\tbreak;\n\t\t}\n\t\tif (segment === \"*\" || segment.includes(\":\")) {\n\t\t\tif (!node.param) node.param = { key: \"*\" };\n\t\t\tnode = node.param;\n\t\t\tif (segment === \"*\") paramsMap.push([\n\t\t\t\ti,\n\t\t\t\t`_${_unnamedParamIndex++}`,\n\t\t\t\ttrue\n\t\t\t]);\n\t\t\telse if (segment.includes(\":\", 1)) {\n\t\t\t\tconst regexp = getParamRegexp(segment);\n\t\t\t\tparamsRegexp[i] = regexp;\n\t\t\t\tnode.hasRegexParam = true;\n\t\t\t\tparamsMap.push([\n\t\t\t\t\ti,\n\t\t\t\t\tregexp,\n\t\t\t\t\tfalse\n\t\t\t\t]);\n\t\t\t} else paramsMap.push([\n\t\t\t\ti,\n\t\t\t\tsegment.slice(1),\n\t\t\t\tfalse\n\t\t\t]);\n\t\t\tcontinue;\n\t\t}\n\t\tconst child = node.static?.[segment];\n\t\tif (child) node = child;\n\t\telse {\n\t\t\tconst staticNode = { key: segment };\n\t\t\tif (!node.static) node.static = new NullProtoObj();\n\t\t\tnode.static[segment] = staticNode;\n\t\t\tnode = staticNode;\n\t\t}\n\t}\n\tconst hasParams = paramsMap.length > 0;\n\tif (!node.methods) node.methods = new NullProtoObj();\n\tnode.methods[method] ??= [];\n\tnode.methods[method].push({\n\t\tdata: data || null,\n\t\tparamsRegexp,\n\t\tparamsMap: hasParams ? paramsMap : void 0\n\t});\n\tif (!hasParams) ctx.static[path] = node;\n}\nfunction getParamRegexp(segment) {\n\tconst regex = segment.replace(/:(\\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\\./g, \"\\\\.\");\n\treturn /* @__PURE__ */ new RegExp(`^${regex}$`);\n}\n\n/**\n* Find a route by path.\n*/\nfunction findRoute(ctx, method = \"\", path, opts) {\n\tif (path.charCodeAt(path.length - 1) === 47) path = path.slice(0, -1);\n\tconst staticNode = ctx.static[path];\n\tif (staticNode && staticNode.methods) {\n\t\tconst staticMatch = staticNode.methods[method] || staticNode.methods[\"\"];\n\t\tif (staticMatch !== void 0) return staticMatch[0];\n\t}\n\tconst segments = splitPath(path);\n\tconst match = _lookupTree(ctx, ctx.root, method, segments, 0)?.[0];\n\tif (match === void 0) return;\n\tif (opts?.params === false) return match;\n\treturn {\n\t\tdata: match.data,\n\t\tparams: match.paramsMap ? getMatchParams(segments, match.paramsMap) : void 0\n\t};\n}\nfunction _lookupTree(ctx, node, method, segments, index) {\n\tif (index === segments.length) {\n\t\tif (node.methods) {\n\t\t\tconst match = node.methods[method] || node.methods[\"\"];\n\t\t\tif (match) return match;\n\t\t}\n\t\tif (node.param && node.param.methods) {\n\t\t\tconst match = node.param.methods[method] || node.param.methods[\"\"];\n\t\t\tif (match) {\n\t\t\t\tconst pMap = match[0].paramsMap;\n\t\t\t\tif (pMap?.[pMap?.length - 1]?.[2]) return match;\n\t\t\t}\n\t\t}\n\t\tif (node.wildcard && node.wildcard.methods) {\n\t\t\tconst match = node.wildcard.methods[method] || node.wildcard.methods[\"\"];\n\t\t\tif (match) {\n\t\t\t\tconst pMap = match[0].paramsMap;\n\t\t\t\tif (pMap?.[pMap?.length - 1]?.[2]) return match;\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\tconst segment = segments[index];\n\tif (node.static) {\n\t\tconst staticChild = node.static[segment];\n\t\tif (staticChild) {\n\t\t\tconst match = _lookupTree(ctx, staticChild, method, segments, index + 1);\n\t\t\tif (match) return match;\n\t\t}\n\t}\n\tif (node.param) {\n\t\tconst match = _lookupTree(ctx, node.param, method, segments, index + 1);\n\t\tif (match) {\n\t\t\tif (node.param.hasRegexParam) {\n\t\t\t\tconst exactMatch = match.find((m) => m.paramsRegexp[index]?.test(segment)) || match.find((m) => !m.paramsRegexp[index]);\n\t\t\t\treturn exactMatch ? [exactMatch] : void 0;\n\t\t\t}\n\t\t\treturn match;\n\t\t}\n\t}\n\tif (node.wildcard && node.wildcard.methods) return node.wildcard.methods[method] || node.wildcard.methods[\"\"];\n}\n\n/**\n* Remove a route from the router context.\n*/\nfunction removeRoute(ctx, method, path) {\n\tconst segments = splitPath(path);\n\treturn _remove(ctx.root, method || \"\", segments, 0);\n}\nfunction _remove(node, method, segments, index) {\n\tif (index === segments.length) {\n\t\tif (node.methods && method in node.methods) {\n\t\t\tdelete node.methods[method];\n\t\t\tif (Object.keys(node.methods).length === 0) node.methods = void 0;\n\t\t}\n\t\treturn;\n\t}\n\tconst segment = segments[index];\n\tif (segment === \"*\") {\n\t\tif (node.param) {\n\t\t\t_remove(node.param, method, segments, index + 1);\n\t\t\tif (_isEmptyNode(node.param)) node.param = void 0;\n\t\t}\n\t\treturn;\n\t}\n\tif (segment.startsWith(\"**\")) {\n\t\tif (node.wildcard) {\n\t\t\t_remove(node.wildcard, method, segments, index + 1);\n\t\t\tif (_isEmptyNode(node.wildcard)) node.wildcard = void 0;\n\t\t}\n\t\treturn;\n\t}\n\tconst childNode = node.static?.[segment];\n\tif (childNode) {\n\t\t_remove(childNode, method, segments, index + 1);\n\t\tif (_isEmptyNode(childNode)) {\n\t\t\tdelete node.static[segment];\n\t\t\tif (Object.keys(node.static).length === 0) node.static = void 0;\n\t\t}\n\t}\n}\nfunction _isEmptyNode(node) {\n\treturn node.methods === void 0 && node.static === void 0 && node.param === void 0 && node.wildcard === void 0;\n}\n\n/**\n* Find all route patterns that match the given path.\n*/\nfunction findAllRoutes(ctx, method = \"\", path, opts) {\n\tif (path.charCodeAt(path.length - 1) === 47) path = path.slice(0, -1);\n\tconst segments = splitPath(path);\n\tconst matches = _findAll(ctx, ctx.root, method, segments, 0);\n\tif (opts?.params === false) return matches;\n\treturn matches.map((m) => {\n\t\treturn {\n\t\t\tdata: m.data,\n\t\t\tparams: m.paramsMap ? getMatchParams(segments, m.paramsMap) : void 0\n\t\t};\n\t});\n}\nfunction _findAll(ctx, node, method, segments, index, matches = []) {\n\tconst segment = segments[index];\n\tif (node.wildcard && node.wildcard.methods) {\n\t\tconst match = node.wildcard.methods[method] || node.wildcard.methods[\"\"];\n\t\tif (match) matches.push(...match);\n\t}\n\tif (node.param) {\n\t\t_findAll(ctx, node.param, method, segments, index + 1, matches);\n\t\tif (index === segments.length && node.param.methods) {\n\t\t\tconst match = node.param.methods[method] || node.param.methods[\"\"];\n\t\t\tif (match) {\n\t\t\t\tconst pMap = match[0].paramsMap;\n\t\t\t\tif (pMap?.[pMap?.length - 1]?.[2]) matches.push(...match);\n\t\t\t}\n\t\t}\n\t}\n\tconst staticChild = node.static?.[segment];\n\tif (staticChild) _findAll(ctx, staticChild, method, segments, index + 1, matches);\n\tif (index === segments.length && node.methods) {\n\t\tconst match = node.methods[method] || node.methods[\"\"];\n\t\tif (match) matches.push(...match);\n\t}\n\treturn matches;\n}\n\nfunction routeToRegExp(route = \"/\") {\n\tconst reSegments = [];\n\tlet idCtr = 0;\n\tfor (const segment of route.split(\"/\")) {\n\t\tif (!segment) continue;\n\t\tif (segment === \"*\") reSegments.push(`(?<_${idCtr++}>[^/]*)`);\n\t\telse if (segment.startsWith(\"**\")) reSegments.push(segment === \"**\" ? \"?(?<_>.*)\" : `?(?<${segment.slice(3)}>.+)`);\n\t\telse if (segment.includes(\":\")) reSegments.push(segment.replace(/:(\\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\\./g, \"\\\\.\"));\n\t\telse reSegments.push(segment);\n\t}\n\treturn /* @__PURE__ */ new RegExp(`^/${reSegments.join(\"/\")}/?$`);\n}\n\nexport { NullProtoObj, addRoute, createRouter, findAllRoutes, findRoute, removeRoute, routeToRegExp };","//#region src/_inherit.ts\nfunction lazyInherit(target, source, sourceKey) {\n\tfor (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {\n\t\tif (key === \"constructor\") continue;\n\t\tconst targetDesc = Object.getOwnPropertyDescriptor(target, key);\n\t\tconst desc = Object.getOwnPropertyDescriptor(source, key);\n\t\tlet modified = false;\n\t\tif (desc.get) {\n\t\t\tmodified = true;\n\t\t\tdesc.get = targetDesc?.get || function() {\n\t\t\t\treturn this[sourceKey][key];\n\t\t\t};\n\t\t}\n\t\tif (desc.set) {\n\t\t\tmodified = true;\n\t\t\tdesc.set = targetDesc?.set || function(value) {\n\t\t\t\tthis[sourceKey][key] = value;\n\t\t\t};\n\t\t}\n\t\tif (!targetDesc?.value && typeof desc.value === \"function\") {\n\t\t\tmodified = true;\n\t\t\tdesc.value = function(...args) {\n\t\t\t\treturn this[sourceKey][key](...args);\n\t\t\t};\n\t\t}\n\t\tif (modified) Object.defineProperty(target, key, desc);\n\t}\n}\n\n//#endregion\nexport { lazyInherit as t };","import { t as lazyInherit } from \"./_inherit-D99WuBbX.mjs\";\n\n//#region src/adapters/_node/response.ts\n/**\n* Fast Response for Node.js runtime\n*\n* It is faster because in most cases it doesn't create a full Response instance.\n*/\nconst NodeResponse = /* @__PURE__ */ (() => {\n\tconst NativeResponse = globalThis.Response;\n\tconst STATUS_CODES = globalThis.process?.getBuiltinModule?.(\"node:http\")?.STATUS_CODES || {};\n\tclass NodeResponse$1 {\n\t\t#body;\n\t\t#init;\n\t\t#headers;\n\t\t#response;\n\t\tconstructor(body, init) {\n\t\t\tthis.#body = body;\n\t\t\tthis.#init = init;\n\t\t}\n\t\tstatic [Symbol.hasInstance](val) {\n\t\t\treturn val instanceof NativeResponse;\n\t\t}\n\t\tget status() {\n\t\t\treturn this.#response?.status || this.#init?.status || 200;\n\t\t}\n\t\tget statusText() {\n\t\t\treturn this.#response?.statusText || this.#init?.statusText || STATUS_CODES[this.status] || \"\";\n\t\t}\n\t\tget headers() {\n\t\t\tif (this.#response) return this.#response.headers;\n\t\t\tif (this.#headers) return this.#headers;\n\t\t\tconst initHeaders = this.#init?.headers;\n\t\t\treturn this.#headers = initHeaders instanceof Headers ? initHeaders : new Headers(initHeaders);\n\t\t}\n\t\tget ok() {\n\t\t\tif (this.#response) return this.#response.ok;\n\t\t\tconst status = this.status;\n\t\t\treturn status >= 200 && status < 300;\n\t\t}\n\t\tget _response() {\n\t\t\tif (this.#response) return this.#response;\n\t\t\tthis.#response = new NativeResponse(this.#body, this.#headers ? {\n\t\t\t\t...this.#init,\n\t\t\t\theaders: this.#headers\n\t\t\t} : this.#init);\n\t\t\tthis.#init = void 0;\n\t\t\tthis.#headers = void 0;\n\t\t\tthis.#body = void 0;\n\t\t\treturn this.#response;\n\t\t}\n\t\t_toNodeResponse() {\n\t\t\tconst status = this.status;\n\t\t\tconst statusText = this.statusText;\n\t\t\tlet body;\n\t\t\tlet contentType;\n\t\t\tlet contentLength;\n\t\t\tif (this.#response) body = this.#response.body;\n\t\t\telse if (this.#body) if (this.#body instanceof ReadableStream) body = this.#body;\n\t\t\telse if (typeof this.#body === \"string\") {\n\t\t\t\tbody = this.#body;\n\t\t\t\tcontentType = \"text/plain; charset=UTF-8\";\n\t\t\t\tcontentLength = Buffer.byteLength(this.#body);\n\t\t\t} else if (this.#body instanceof ArrayBuffer) {\n\t\t\t\tbody = Buffer.from(this.#body);\n\t\t\t\tcontentLength = this.#body.byteLength;\n\t\t\t} else if (this.#body instanceof Uint8Array) {\n\t\t\t\tbody = this.#body;\n\t\t\t\tcontentLength = this.#body.byteLength;\n\t\t\t} else if (this.#body instanceof DataView) {\n\t\t\t\tbody = Buffer.from(this.#body.buffer);\n\t\t\t\tcontentLength = this.#body.byteLength;\n\t\t\t} else if (this.#body instanceof Blob) {\n\t\t\t\tbody = this.#body.stream();\n\t\t\t\tcontentType = this.#body.type;\n\t\t\t\tcontentLength = this.#body.size;\n\t\t\t} else if (typeof this.#body.pipe === \"function\") body = this.#body;\n\t\t\telse body = this._response.body;\n\t\t\tconst headers = [];\n\t\t\tconst initHeaders = this.#init?.headers;\n\t\t\tconst headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders).map(([k, v]) => [k.toLowerCase(), v]) : void 0);\n\t\t\tlet hasContentTypeHeader;\n\t\t\tlet hasContentLength;\n\t\t\tif (headerEntries) for (const [key, value] of headerEntries) {\n\t\t\t\tif (Array.isArray(value)) for (const v of value) headers.push([key, v]);\n\t\t\t\telse headers.push([key, value]);\n\t\t\t\tif (key === \"content-type\") hasContentTypeHeader = true;\n\t\t\t\telse if (key === \"content-length\") hasContentLength = true;\n\t\t\t}\n\t\t\tif (contentType && !hasContentTypeHeader) headers.push([\"content-type\", contentType]);\n\t\t\tif (contentLength && !hasContentLength) headers.push([\"content-length\", String(contentLength)]);\n\t\t\tthis.#init = void 0;\n\t\t\tthis.#headers = void 0;\n\t\t\tthis.#response = void 0;\n\t\t\tthis.#body = void 0;\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tstatusText,\n\t\t\t\theaders,\n\t\t\t\tbody\n\t\t\t};\n\t\t}\n\t}\n\tlazyInherit(NodeResponse$1.prototype, NativeResponse.prototype, \"_response\");\n\tObject.setPrototypeOf(NodeResponse$1, NativeResponse);\n\tObject.setPrototypeOf(NodeResponse$1.prototype, NativeResponse.prototype);\n\treturn NodeResponse$1;\n})();\n\n//#endregion\n//#region src/adapters/_node/call.ts\nfunction callNodeHandler(handler, req) {\n\tconst isMiddleware = handler.length > 2;\n\tconst nodeCtx = req.runtime?.node;\n\tif (!nodeCtx || !nodeCtx.req || !nodeCtx.res) throw new Error(\"Node.js runtime context is not available.\");\n\tconst { req: nodeReq, res: nodeRes } = nodeCtx;\n\tlet _headers;\n\tconst webRes = new NodeResponse(void 0, {\n\t\tget status() {\n\t\t\treturn nodeRes.statusCode;\n\t\t},\n\t\tget statusText() {\n\t\t\treturn nodeRes.statusMessage;\n\t\t},\n\t\tget headers() {\n\t\t\tif (!_headers) {\n\t\t\t\tconst headerEntries = [];\n\t\t\t\tconst rawHeaders = nodeRes.getHeaders();\n\t\t\t\tfor (const [name, value] of Object.entries(rawHeaders)) if (Array.isArray(value)) for (const v of value) headerEntries.push([name, v]);\n\t\t\t\telse if (value) headerEntries.push([name, String(value)]);\n\t\t\t\t_headers = new Headers(headerEntries);\n\t\t\t}\n\t\t\treturn _headers;\n\t\t}\n\t});\n\treturn new Promise((resolve, reject) => {\n\t\tnodeRes.once(\"close\", () => resolve(webRes));\n\t\tnodeRes.once(\"finish\", () => resolve(webRes));\n\t\tnodeRes.once(\"error\", (error) => reject(error));\n\t\tlet streamPromise;\n\t\tnodeRes.once(\"pipe\", (stream) => {\n\t\t\tstreamPromise = new Promise((resolve$1) => {\n\t\t\t\tstream.once(\"end\", () => resolve$1(webRes));\n\t\t\t\tstream.once(\"error\", (error) => reject(error));\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tif (isMiddleware) Promise.resolve(handler(nodeReq, nodeRes, (error) => error ? reject(error) : streamPromise || resolve(webRes))).catch((error) => reject(error));\n\t\t\telse Promise.resolve(handler(nodeReq, nodeRes)).then(() => streamPromise || webRes);\n\t\t} catch (error) {\n\t\t\treject(error);\n\t\t}\n\t});\n}\n\n//#endregion\nexport { NodeResponse as n, callNodeHandler as t };","import { NullProtoObj as EmptyObject, addRoute, createRouter, findRoute, routeToRegExp } from \"rou3\";\nimport { FastResponse, FastURL } from \"srvx\";\n\nfunction freezeApp(app) {\n\tapp.config = Object.freeze(app.config);\n\tapp[\"~addRoute\"] = () => {\n\t\tthrow new Error(\"Cannot add routes after the server init.\");\n\t};\n}\n\nfunction definePlugin(def) {\n\treturn ((opts) => (h3) => def(h3, opts));\n}\n\nconst kEventNS = \"h3.internal.event.\";\nconst kEventRes = /* @__PURE__ */ Symbol.for(`${kEventNS}res`);\nconst kEventResHeaders = /* @__PURE__ */ Symbol.for(`${kEventNS}res.headers`);\nvar H3Event = class {\n\t\n\tapp;\n\t\n\treq;\n\t\n\turl;\n\t\n\tcontext;\n\t\n\tstatic __is_event__ = true;\n\tconstructor(req, context, app) {\n\t\tthis.context = context || req.context || new EmptyObject();\n\t\tthis.req = req;\n\t\tthis.app = app;\n\t\tconst _url = req._url;\n\t\tthis.url = _url && _url instanceof URL ? _url : new FastURL(req.url);\n\t}\n\t\n\tget res() {\n\t\treturn this[kEventRes] ||= new H3EventResponse();\n\t}\n\t\n\tget runtime() {\n\t\treturn this.req.runtime;\n\t}\n\t\n\twaitUntil(promise) {\n\t\tthis.req.waitUntil?.(promise);\n\t}\n\ttoString() {\n\t\treturn `[${this.req.method}] ${this.req.url}`;\n\t}\n\ttoJSON() {\n\t\treturn this.toString();\n\t}\n\t\n\tget node() {\n\t\treturn this.req.runtime?.node;\n\t}\n\t\n\tget headers() {\n\t\treturn this.req.headers;\n\t}\n\t\n\tget path() {\n\t\treturn this.url.pathname + this.url.search;\n\t}\n\t\n\tget method() {\n\t\treturn this.req.method;\n\t}\n};\nvar H3EventResponse = class {\n\tstatus;\n\tstatusText;\n\tget headers() {\n\t\treturn this[kEventResHeaders] ||= new Headers();\n\t}\n};\n\nconst DISALLOWED_STATUS_CHARS = /[^\\u0009\\u0020-\\u007E]/g;\n\nfunction sanitizeStatusMessage(statusMessage = \"\") {\n\treturn statusMessage.replace(DISALLOWED_STATUS_CHARS, \"\");\n}\n\nfunction sanitizeStatusCode(statusCode, defaultStatusCode = 200) {\n\tif (!statusCode) return defaultStatusCode;\n\tif (typeof statusCode === \"string\") statusCode = +statusCode;\n\tif (statusCode < 100 || statusCode > 599) return defaultStatusCode;\n\treturn statusCode;\n}\n\n\nvar HTTPError = class HTTPError extends Error {\n\tget name() {\n\t\treturn \"HTTPError\";\n\t}\n\t\n\tstatus;\n\t\n\tstatusText;\n\t\n\theaders;\n\t\n\tcause;\n\t\n\tdata;\n\t\n\tbody;\n\t\n\tunhandled;\n\t\n\tstatic isError(input) {\n\t\treturn input instanceof Error && input?.name === \"HTTPError\";\n\t}\n\t\n\tstatic status(status, statusText, details) {\n\t\treturn new HTTPError({\n\t\t\t...details,\n\t\t\tstatusText,\n\t\t\tstatus\n\t\t});\n\t}\n\tconstructor(arg1, arg2) {\n\t\tlet messageInput;\n\t\tlet details;\n\t\tif (typeof arg1 === \"string\") {\n\t\t\tmessageInput = arg1;\n\t\t\tdetails = arg2;\n\t\t} else details = arg1;\n\t\tconst status = sanitizeStatusCode(details?.status || (details?.cause)?.status || details?.status || details?.statusCode, 500);\n\t\tconst statusText = sanitizeStatusMessage(details?.statusText || (details?.cause)?.statusText || details?.statusText || details?.statusMessage);\n\t\tconst message = messageInput || details?.message || (details?.cause)?.message || details?.statusText || details?.statusMessage || [\n\t\t\t\"HTTPError\",\n\t\t\tstatus,\n\t\t\tstatusText\n\t\t].filter(Boolean).join(\" \");\n\t\tsuper(message, { cause: details });\n\t\tthis.cause = details;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t\tthis.status = status;\n\t\tthis.statusText = statusText || void 0;\n\t\tconst rawHeaders = details?.headers || (details?.cause)?.headers;\n\t\tthis.headers = rawHeaders ? new Headers(rawHeaders) : void 0;\n\t\tthis.unhandled = details?.unhandled ?? (details?.cause)?.unhandled ?? void 0;\n\t\tthis.data = details?.data;\n\t\tthis.body = details?.body;\n\t}\n\t\n\tget statusCode() {\n\t\treturn this.status;\n\t}\n\t\n\tget statusMessage() {\n\t\treturn this.statusText;\n\t}\n\ttoJSON() {\n\t\tconst unhandled = this.unhandled;\n\t\treturn {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t\tunhandled,\n\t\t\tmessage: unhandled ? \"HTTPError\" : this.message,\n\t\t\tdata: unhandled ? void 0 : this.data,\n\t\t\t...unhandled ? void 0 : this.body\n\t\t};\n\t}\n};\n\n\nfunction hasProp(obj, prop) {\n\ttry {\n\t\treturn prop in obj;\n\t} catch {\n\t\treturn false;\n\t}\n}\nfunction isJSONSerializable(value, _type) {\n\tif (value === null || value === void 0) return true;\n\tif (_type !== \"object\") return _type === \"boolean\" || _type === \"number\" || _type === \"string\";\n\tif (typeof value.toJSON === \"function\") return true;\n\tif (Array.isArray(value)) return true;\n\tif (typeof value.pipe === \"function\" || typeof value.pipeTo === \"function\") return false;\n\tif (value instanceof EmptyObject) return true;\n\tconst proto = Object.getPrototypeOf(value);\n\treturn proto === Object.prototype || proto === null;\n}\n\nconst kNotFound = /* @__PURE__ */ Symbol.for(\"h3.notFound\");\nconst kHandled = /* @__PURE__ */ Symbol.for(\"h3.handled\");\nfunction toResponse(val, event, config = {}) {\n\tif (typeof val?.then === \"function\") return (val.catch?.((error) => error) || Promise.resolve(val)).then((resolvedVal) => toResponse(resolvedVal, event, config));\n\tconst response = prepareResponse(val, event, config);\n\tif (typeof response?.then === \"function\") return toResponse(response, event, config);\n\tconst { onResponse: onResponse$1 } = config;\n\treturn onResponse$1 ? Promise.resolve(onResponse$1(response, event)).then(() => response) : response;\n}\nvar HTTPResponse = class {\n\t#headers;\n\t#init;\n\tbody;\n\tconstructor(body, init) {\n\t\tthis.body = body;\n\t\tthis.#init = init;\n\t}\n\tget status() {\n\t\treturn this.#init?.status || 200;\n\t}\n\tget statusText() {\n\t\treturn this.#init?.statusText || \"OK\";\n\t}\n\tget headers() {\n\t\treturn this.#headers ||= new Headers(this.#init?.headers);\n\t}\n};\nfunction prepareResponse(val, event, config, nested) {\n\tif (val === kHandled) return new FastResponse(null);\n\tif (val === kNotFound) val = new HTTPError({\n\t\tstatus: 404,\n\t\tmessage: `Cannot find any route matching [${event.req.method}] ${event.url}`\n\t});\n\tif (val && val instanceof Error) {\n\t\tconst isHTTPError = HTTPError.isError(val);\n\t\tconst error = isHTTPError ? val : new HTTPError(val);\n\t\tif (!isHTTPError) {\n\t\t\terror.unhandled = true;\n\t\t\tif (val?.stack) error.stack = val.stack;\n\t\t}\n\t\tif (error.unhandled && !config.silent) console.error(error);\n\t\tconst { onError: onError$1 } = config;\n\t\treturn onError$1 && !nested ? Promise.resolve(onError$1(error, event)).catch((error$1) => error$1).then((newVal) => prepareResponse(newVal ?? val, event, config, true)) : errorResponse(error, config.debug);\n\t}\n\tconst preparedRes = event[kEventRes];\n\tconst preparedHeaders = preparedRes?.[kEventResHeaders];\n\tif (!(val instanceof Response)) {\n\t\tconst res = prepareResponseBody(val, event, config);\n\t\tconst status = res.status || preparedRes?.status;\n\t\treturn new FastResponse(nullBody(event.req.method, status) ? null : res.body, {\n\t\t\tstatus,\n\t\t\tstatusText: res.statusText || preparedRes?.statusText,\n\t\t\theaders: res.headers && preparedHeaders ? mergeHeaders$1(res.headers, preparedHeaders) : res.headers || preparedHeaders\n\t\t});\n\t}\n\tif (!preparedHeaders || nested || !val.ok) return val;\n\ttry {\n\t\tmergeHeaders$1(val.headers, preparedHeaders, val.headers);\n\t\treturn val;\n\t} catch {\n\t\treturn new FastResponse(nullBody(event.req.method, val.status) ? null : val.body, {\n\t\t\tstatus: val.status,\n\t\t\tstatusText: val.statusText,\n\t\t\theaders: mergeHeaders$1(val.headers, preparedHeaders)\n\t\t});\n\t}\n}\nfunction mergeHeaders$1(base, overrides, target = new Headers(base)) {\n\tfor (const [name, value] of overrides) if (name === \"set-cookie\") target.append(name, value);\n\telse target.set(name, value);\n\treturn target;\n}\nconst frozenHeaders = () => {\n\tthrow new Error(\"Headers are frozen\");\n};\nvar FrozenHeaders = class extends Headers {\n\tconstructor(init) {\n\t\tsuper(init);\n\t\tthis.set = this.append = this.delete = frozenHeaders;\n\t}\n};\nconst emptyHeaders = /* @__PURE__ */ new FrozenHeaders({ \"content-length\": \"0\" });\nconst jsonHeaders = /* @__PURE__ */ new FrozenHeaders({ \"content-type\": \"application/json;charset=UTF-8\" });\nfunction prepareResponseBody(val, event, config) {\n\tif (val === null || val === void 0) return {\n\t\tbody: \"\",\n\t\theaders: emptyHeaders\n\t};\n\tconst valType = typeof val;\n\tif (valType === \"string\") return { body: val };\n\tif (val instanceof Uint8Array) {\n\t\tevent.res.headers.set(\"content-length\", val.byteLength.toString());\n\t\treturn { body: val };\n\t}\n\tif (val instanceof HTTPResponse || val?.constructor?.name === \"HTTPResponse\") return val;\n\tif (isJSONSerializable(val, valType)) return {\n\t\tbody: JSON.stringify(val, void 0, config.debug ? 2 : void 0),\n\t\theaders: jsonHeaders\n\t};\n\tif (valType === \"bigint\") return {\n\t\tbody: val.toString(),\n\t\theaders: jsonHeaders\n\t};\n\tif (val instanceof Blob) {\n\t\tconst headers = new Headers({\n\t\t\t\"content-type\": val.type,\n\t\t\t\"content-length\": val.size.toString()\n\t\t});\n\t\tlet filename = val.name;\n\t\tif (filename) {\n\t\t\tfilename = encodeURIComponent(filename);\n\t\t\theaders.set(\"content-disposition\", `filename=\"${filename}\"; filename*=UTF-8''${filename}`);\n\t\t}\n\t\treturn {\n\t\t\tbody: val.stream(),\n\t\t\theaders\n\t\t};\n\t}\n\tif (valType === \"symbol\") return { body: val.toString() };\n\tif (valType === \"function\") return { body: `${val.name}()` };\n\treturn { body: val };\n}\nfunction nullBody(method, status) {\n\treturn method === \"HEAD\" || status === 100 || status === 101 || status === 102 || status === 204 || status === 205 || status === 304;\n}\nfunction errorResponse(error, debug) {\n\treturn new FastResponse(JSON.stringify({\n\t\t...error.toJSON(),\n\t\tstack: debug && error.stack ? error.stack.split(\"\\n\").map((l) => l.trim()) : void 0\n\t}, void 0, debug ? 2 : void 0), {\n\t\tstatus: error.status,\n\t\tstatusText: error.statusText,\n\t\theaders: error.headers ? mergeHeaders$1(jsonHeaders, error.headers) : new Headers(jsonHeaders)\n\t});\n}\n\nfunction defineMiddleware(input) {\n\treturn input;\n}\nfunction normalizeMiddleware(input, opts = {}) {\n\tconst matcher = createMatcher(opts);\n\tif (!matcher && (input.length > 1 || input.constructor?.name === \"AsyncFunction\")) return input;\n\treturn (event, next) => {\n\t\tif (matcher && !matcher(event)) return next();\n\t\tconst res = input(event, next);\n\t\treturn res === void 0 || res === kNotFound ? next() : res;\n\t};\n}\nfunction createMatcher(opts) {\n\tif (!opts.route && !opts.method && !opts.match) return;\n\tconst routeMatcher = opts.route ? routeToRegExp(opts.route) : void 0;\n\tconst method = opts.method?.toUpperCase();\n\treturn function _middlewareMatcher(event) {\n\t\tif (method && event.req.method !== method) return false;\n\t\tif (opts.match && !opts.match(event)) return false;\n\t\tif (!routeMatcher) return true;\n\t\tconst match = event.url.pathname.match(routeMatcher);\n\t\tif (!match) return false;\n\t\tif (match.groups) event.context.middlewareParams = {\n\t\t\t...event.context.middlewareParams,\n\t\t\t...match.groups\n\t\t};\n\t\treturn true;\n\t};\n}\nfunction callMiddleware(event, middleware, handler, index = 0) {\n\tif (index === middleware.length) return handler(event);\n\tconst fn = middleware[index];\n\tlet nextCalled;\n\tlet nextResult;\n\tconst next = () => {\n\t\tif (nextCalled) return nextResult;\n\t\tnextCalled = true;\n\t\tnextResult = callMiddleware(event, middleware, handler, index + 1);\n\t\treturn nextResult;\n\t};\n\tconst ret = fn(event, next);\n\treturn isUnhandledResponse(ret) ? next() : typeof ret?.then === \"function\" ? ret.then((resolved) => isUnhandledResponse(resolved) ? next() : resolved) : ret;\n}\nfunction isUnhandledResponse(val) {\n\treturn val === void 0 || val === kNotFound;\n}\n\nfunction toMiddleware(input) {\n\tlet h = input.handler || input;\n\tlet isFunction = typeof h === \"function\";\n\tif (!isFunction && typeof input?.fetch === \"function\") {\n\t\tisFunction = true;\n\t\th = function _fetchHandler(event) {\n\t\t\treturn input.fetch(event.req);\n\t\t};\n\t}\n\tif (!isFunction) return function noopMiddleware(event, next) {\n\t\treturn next();\n\t};\n\tif (h.length === 2) return h;\n\treturn function _middlewareHandler(event, next) {\n\t\tconst res = h(event);\n\t\treturn typeof res?.then === \"function\" ? res.then((r) => {\n\t\t\treturn is404(r) ? next() : r;\n\t\t}) : is404(res) ? next() : res;\n\t};\n}\nfunction is404(val) {\n\treturn isUnhandledResponse(val) || val?.status === 404 && val instanceof Response;\n}\n\nconst plusRegex = /\\+/g;\nfunction parseQuery(input) {\n\tconst params = new EmptyObject();\n\tif (!input || input === \"?\") return params;\n\tconst inputLength = input.length;\n\tlet key = \"\";\n\tlet value = \"\";\n\tlet startingIndex = -1;\n\tlet equalityIndex = -1;\n\tlet shouldDecodeKey = false;\n\tlet shouldDecodeValue = false;\n\tlet keyHasPlus = false;\n\tlet valueHasPlus = false;\n\tlet hasBothKeyValuePair = false;\n\tlet c = 0;\n\tfor (let i = 0; i < inputLength + 1; i++) {\n\t\tc = i === inputLength ? 38 : input.charCodeAt(i);\n\t\tswitch (c) {\n\t\t\tcase 38:\n\t\t\t\thasBothKeyValuePair = equalityIndex > startingIndex;\n\t\t\t\tif (!hasBothKeyValuePair) equalityIndex = i;\n\t\t\t\tkey = input.slice(startingIndex + 1, equalityIndex);\n\t\t\t\tif (hasBothKeyValuePair || key.length > 0) {\n\t\t\t\t\tif (keyHasPlus) key = key.replace(plusRegex, \" \");\n\t\t\t\t\tif (shouldDecodeKey) try {\n\t\t\t\t\t\tkey = decodeURIComponent(key);\n\t\t\t\t\t} catch {}\n\t\t\t\t\tif (hasBothKeyValuePair) {\n\t\t\t\t\t\tvalue = input.slice(equalityIndex + 1, i);\n\t\t\t\t\t\tif (valueHasPlus) value = value.replace(plusRegex, \" \");\n\t\t\t\t\t\tif (shouldDecodeValue) try {\n\t\t\t\t\t\t\tvalue = decodeURIComponent(value);\n\t\t\t\t\t\t} catch {}\n\t\t\t\t\t}\n\t\t\t\t\tconst currentValue = params[key];\n\t\t\t\t\tif (currentValue === void 0) params[key] = value;\n\t\t\t\t\telse if (Array.isArray(currentValue)) currentValue.push(value);\n\t\t\t\t\telse params[key] = [currentValue, value];\n\t\t\t\t}\n\t\t\t\tvalue = \"\";\n\t\t\t\tstartingIndex = i;\n\t\t\t\tequalityIndex = i;\n\t\t\t\tshouldDecodeKey = false;\n\t\t\t\tshouldDecodeValue = false;\n\t\t\t\tkeyHasPlus = false;\n\t\t\t\tvalueHasPlus = false;\n\t\t\t\tbreak;\n\t\t\tcase 61:\n\t\t\t\tif (equalityIndex <= startingIndex) equalityIndex = i;\n\t\t\t\telse shouldDecodeValue = true;\n\t\t\t\tbreak;\n\t\t\tcase 43:\n\t\t\t\tif (equalityIndex > startingIndex) valueHasPlus = true;\n\t\t\t\telse keyHasPlus = true;\n\t\t\t\tbreak;\n\t\t\tcase 37:\n\t\t\t\tif (equalityIndex > startingIndex) shouldDecodeValue = true;\n\t\t\t\telse shouldDecodeKey = true;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn params;\n}\n\nasync function validateData(data, fn) {\n\tif (\"~standard\" in fn) {\n\t\tconst result = await fn[\"~standard\"].validate(data);\n\t\tif (result.issues) throw createValidationError({\n\t\t\tmessage: \"Validation failed\",\n\t\t\tissues: result.issues\n\t\t});\n\t\treturn result.value;\n\t}\n\ttry {\n\t\tconst res = await fn(data);\n\t\tif (res === false) throw createValidationError({ message: \"Validation failed\" });\n\t\tif (res === true) return data;\n\t\treturn res ?? data;\n\t} catch (error) {\n\t\tthrow createValidationError(error);\n\t}\n}\nconst reqBodyKeys = new Set([\n\t\"body\",\n\t\"text\",\n\t\"formData\",\n\t\"arrayBuffer\"\n]);\nfunction validatedRequest(req, validate) {\n\tif (validate.headers) {\n\t\tconst validatedheaders = syncValidate(\"headers\", Object.fromEntries(req.headers.entries()), validate.headers);\n\t\tfor (const [key, value] of Object.entries(validatedheaders)) req.headers.set(key, value);\n\t}\n\tif (!validate.body) return req;\n\treturn new Proxy(req, { get(_target, prop) {\n\t\tif (validate.body) {\n\t\t\tif (prop === \"json\") return function _validatedJson() {\n\t\t\t\treturn req.json().then((data) => validate.body[\"~standard\"].validate(data)).then((result) => result.issues ? Promise.reject(createValidationError(result)) : result.value);\n\t\t\t};\n\t\t\telse if (reqBodyKeys.has(prop)) throw new TypeError(`Cannot access .${prop} on request with JSON validation enabled. Use .json() instead.`);\n\t\t}\n\t\treturn Reflect.get(req, prop);\n\t} });\n}\nfunction validatedURL(url, validate) {\n\tif (!validate.query) return url;\n\tconst validatedQuery = syncValidate(\"query\", Object.fromEntries(url.searchParams.entries()), validate.query);\n\tfor (const [key, value] of Object.entries(validatedQuery)) url.searchParams.set(key, value);\n\treturn url;\n}\nfunction syncValidate(type, data, fn) {\n\tconst result = fn[\"~standard\"].validate(data);\n\tif (result instanceof Promise) throw new TypeError(`Asynchronous validation is not supported for ${type}`);\n\tif (result.issues) throw createValidationError({ issues: result.issues });\n\treturn result.value;\n}\nfunction createValidationError(validateError) {\n\treturn new HTTPError({\n\t\tstatus: 400,\n\t\tstatusText: \"Validation failed\",\n\t\tmessage: validateError?.message,\n\t\tdata: validateError,\n\t\tcause: validateError\n\t});\n}\n\n\nfunction isEvent(input) {\n\treturn input instanceof H3Event || input?.constructor?.__is_event__;\n}\n\nfunction isHTTPEvent(input) {\n\treturn input?.req instanceof Request;\n}\n\nfunction getEventContext(event) {\n\tif (event.context) return event.context;\n\tevent.req.context ??= {};\n\treturn event.req.context;\n}\nfunction mockEvent(_request, options) {\n\tlet request;\n\tif (typeof _request === \"string\") {\n\t\tlet url = _request;\n\t\tif (url[0] === \"/\") url = `http://localhost${url}`;\n\t\trequest = new Request(url, options);\n\t} else if (options || _request instanceof URL) request = new Request(_request, options);\n\telse request = _request;\n\treturn new H3Event(request);\n}\n\n\nfunction toRequest(input, options) {\n\tif (typeof input === \"string\") {\n\t\tlet url = input;\n\t\tif (url[0] === \"/\") {\n\t\t\tconst headers = options?.headers ? new Headers(options.headers) : void 0;\n\t\t\tconst host = headers?.get(\"host\") || \"localhost\";\n\t\t\turl = `${headers?.get(\"x-forwarded-proto\") === \"https\" ? \"https\" : \"http\"}://${host}${url}`;\n\t\t}\n\t\treturn new Request(url, options);\n\t} else if (options || input instanceof URL) return new Request(input, options);\n\treturn input;\n}\n\nfunction getQuery(event) {\n\treturn parseQuery((event.url || new URL(event.req.url)).search.slice(1));\n}\n\nfunction getValidatedQuery(event, validate) {\n\treturn validateData(getQuery(event), validate);\n}\n\nfunction getRouterParams(event, opts = {}) {\n\tlet params = getEventContext(event).params || {};\n\tif (opts.decode) {\n\t\tparams = { ...params };\n\t\tfor (const key in params) params[key] = decodeURIComponent(params[key]);\n\t}\n\treturn params;\n}\n\nfunction getValidatedRouterParams(event, validate, opts = {}) {\n\treturn validateData(getRouterParams(event, opts), validate);\n}\n\nfunction getRouterParam(event, name, opts = {}) {\n\treturn getRouterParams(event, opts)[name];\n}\n\nfunction isMethod(event, expected, allowHead) {\n\tif (allowHead && event.req.method === \"HEAD\") return true;\n\tif (typeof expected === \"string\") {\n\t\tif (event.req.method === expected) return true;\n\t} else if (expected.includes(event.req.method)) return true;\n\treturn false;\n}\n\nfunction assertMethod(event, expected, allowHead) {\n\tif (!isMethod(event, expected, allowHead)) throw new HTTPError({ status: 405 });\n}\n\nfunction getRequestHost(event, opts = {}) {\n\tif (opts.xForwardedHost) {\n\t\tconst xForwardedHost = (event.req.headers.get(\"x-forwarded-host\") || \"\").split(\",\").shift()?.trim();\n\t\tif (xForwardedHost) return xForwardedHost;\n\t}\n\treturn event.req.headers.get(\"host\") || \"\";\n}\n\nfunction getRequestProtocol(event, opts = {}) {\n\tif (opts.xForwardedProto !== false) {\n\t\tconst forwardedProto = event.req.headers.get(\"x-forwarded-proto\");\n\t\tif (forwardedProto === \"https\") return \"https\";\n\t\tif (forwardedProto === \"http\") return \"http\";\n\t}\n\treturn (event.url || new URL(event.req.url)).protocol.slice(0, -1);\n}\n\nfunction getRequestURL(event, opts = {}) {\n\tconst url = new URL(event.url || event.req.url);\n\turl.protocol = getRequestProtocol(event, opts);\n\tif (opts.xForwardedHost) {\n\t\tconst host = getRequestHost(event, opts);\n\t\tif (host) {\n\t\t\turl.host = host;\n\t\t\tif (!host.includes(\":\")) url.port = \"\";\n\t\t}\n\t}\n\treturn url;\n}\n\nfunction getRequestIP(event, opts = {}) {\n\tif (opts.xForwardedFor) {\n\t\tconst _header = event.req.headers.get(\"x-forwarded-for\");\n\t\tif (_header) {\n\t\t\tconst xForwardedFor = _header.split(\",\")[0].trim();\n\t\t\tif (xForwardedFor) return xForwardedFor;\n\t\t}\n\t}\n\treturn event.req.context?.clientAddress || event.req.ip || void 0;\n}\n\nfunction defineHandler(input) {\n\tif (typeof input === \"function\") return handlerWithFetch(input);\n\tconst handler = input.handler || (input.fetch ? function _fetchHandler(event) {\n\t\treturn input.fetch(event.req);\n\t} : NoHandler);\n\treturn Object.assign(handlerWithFetch(input.middleware?.length ? function _handlerMiddleware(event) {\n\t\treturn callMiddleware(event, input.middleware, handler);\n\t} : handler), input);\n}\n\nfunction defineValidatedHandler(def) {\n\tif (!def.validate) return defineHandler(def);\n\treturn defineHandler({\n\t\t...def,\n\t\thandler: function _validatedHandler(event) {\n\t\t\tevent.req = validatedRequest(event.req, def.validate);\n\t\t\tevent.url = validatedURL(event.url, def.validate);\n\t\t\treturn def.handler(event);\n\t\t}\n\t});\n}\nfunction handlerWithFetch(handler) {\n\tif (\"fetch\" in handler) return handler;\n\treturn Object.assign(handler, { fetch: (req) => {\n\t\tif (typeof req === \"string\") req = new URL(req, \"http://_\");\n\t\tif (req instanceof URL) req = new Request(req);\n\t\tconst event = new H3Event(req);\n\t\ttry {\n\t\t\treturn Promise.resolve(toResponse(handler(event), event));\n\t\t} catch (error) {\n\t\t\treturn Promise.resolve(toResponse(error, event));\n\t\t}\n\t} });\n}\nfunction dynamicEventHandler(initial) {\n\tlet current = toEventHandler(initial);\n\treturn Object.assign(defineHandler(function _dynamicEventHandler(event) {\n\t\treturn current?.(event);\n\t}), { set: (handler) => {\n\t\tcurrent = toEventHandler(handler);\n\t} });\n}\nfunction defineLazyEventHandler(loader) {\n\tlet handler;\n\tlet promise;\n\tconst resolveLazyHandler = () => {\n\t\tif (handler) return Promise.resolve(handler);\n\t\treturn promise ??= Promise.resolve(loader()).then((r) => {\n\t\t\thandler = toEventHandler(r) || toEventHandler(r.default);\n\t\t\tif (typeof handler !== \"function\") throw new TypeError(\"Invalid lazy handler\", { cause: { resolved: r } });\n\t\t\treturn handler;\n\t\t});\n\t};\n\treturn defineHandler(function lazyHandler(event) {\n\t\treturn handler ? handler(event) : resolveLazyHandler().then((r) => r(event));\n\t});\n}\nfunction toEventHandler(handler) {\n\tif (typeof handler === \"function\") return handler;\n\tif (typeof handler?.handler === \"function\") return handler.handler;\n\tif (typeof handler?.fetch === \"function\") return function _fetchHandler(event) {\n\t\treturn handler.fetch(event.req);\n\t};\n}\n\nconst NoHandler = () => kNotFound;\nvar H3Core = class {\n\tconfig;\n\t\"~middleware\";\n\t\"~routes\" = [];\n\tconstructor(config = {}) {\n\t\tthis[\"~middleware\"] = [];\n\t\tthis.config = config;\n\t\tthis.fetch = this.fetch.bind(this);\n\t\tthis.handler = this.handler.bind(this);\n\t}\n\tfetch(request) {\n\t\treturn this[\"~request\"](request);\n\t}\n\thandler(event) {\n\t\tconst route = this[\"~findRoute\"](event);\n\t\tif (route) {\n\t\t\tevent.context.params = route.params;\n\t\t\tevent.context.matchedRoute = route.data;\n\t\t}\n\t\tconst routeHandler = route?.data.handler || NoHandler;\n\t\tconst middleware = this[\"~getMiddleware\"](event, route);\n\t\treturn middleware.length > 0 ? callMiddleware(event, middleware, routeHandler) : routeHandler(event);\n\t}\n\t\"~request\"(request, context) {\n\t\tconst event = new H3Event(request, context, this);\n\t\tlet handlerRes;\n\t\ttry {\n\t\t\tif (this.config.onRequest) {\n\t\t\t\tconst hookRes = this.config.onRequest(event);\n\t\t\t\thandlerRes = typeof hookRes?.then === \"function\" ? hookRes.then(() => this.handler(event)) : this.handler(event);\n\t\t\t} else handlerRes = this.handler(event);\n\t\t} catch (error) {\n\t\t\thandlerRes = Promise.reject(error);\n\t\t}\n\t\treturn toResponse(handlerRes, event, this.config);\n\t}\n\t\"~findRoute\"(_event) {}\n\t\"~addRoute\"(_route) {\n\t\tthis[\"~routes\"].push(_route);\n\t}\n\t\"~getMiddleware\"(_event, route) {\n\t\tconst routeMiddleware = route?.data.middleware;\n\t\tconst globalMiddleware = this[\"~middleware\"];\n\t\treturn routeMiddleware ? [...globalMiddleware, ...routeMiddleware] : globalMiddleware;\n\t}\n};\nconst H3 = /* @__PURE__ */ (() => {\n\tclass H3$1 extends H3Core {\n\t\t\"~rou3\";\n\t\tconstructor(config = {}) {\n\t\t\tsuper(config);\n\t\t\tthis[\"~rou3\"] = createRouter();\n\t\t\tthis.request = this.request.bind(this);\n\t\t\tconfig.plugins?.forEach((plugin) => plugin(this));\n\t\t}\n\t\tregister(plugin) {\n\t\t\tplugin(this);\n\t\t\treturn this;\n\t\t}\n\t\trequest(_req, _init, context) {\n\t\t\treturn this[\"~request\"](toRequest(_req, _init), context);\n\t\t}\n\t\tmount(base, input) {\n\t\t\tif (\"handler\" in input) {\n\t\t\t\tif (input[\"~middleware\"].length > 0) this[\"~middleware\"].push((event, next) => {\n\t\t\t\t\tconst originalPathname = event.url.pathname;\n\t\t\t\t\tif (!originalPathname.startsWith(base)) return next();\n\t\t\t\t\tevent.url.pathname = event.url.pathname.slice(base.length) || \"/\";\n\t\t\t\t\treturn callMiddleware(event, input[\"~middleware\"], () => {\n\t\t\t\t\t\tevent.url.pathname = originalPathname;\n\t\t\t\t\t\treturn next();\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tfor (const r of input[\"~routes\"]) this[\"~addRoute\"]({\n\t\t\t\t\t...r,\n\t\t\t\t\troute: base + r.route\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst fetchHandler = \"fetch\" in input ? input.fetch : input;\n\t\t\t\tthis.all(`${base}/**`, function _mountedMiddleware(event) {\n\t\t\t\t\tconst url = new URL(event.url);\n\t\t\t\t\turl.pathname = url.pathname.slice(base.length) || \"/\";\n\t\t\t\t\treturn fetchHandler(new Request(url, event.req));\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t\ton(method, route, handler, opts) {\n\t\t\tconst _method = (method || \"\").toUpperCase();\n\t\t\troute = new URL(route, \"http://_\").pathname;\n\t\t\tthis[\"~addRoute\"]({\n\t\t\t\tmethod: _method,\n\t\t\t\troute,\n\t\t\t\thandler: toEventHandler(handler),\n\t\t\t\tmiddleware: opts?.middleware,\n\t\t\t\tmeta: {\n\t\t\t\t\t...handler.meta,\n\t\t\t\t\t...opts?.meta\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn this;\n\t\t}\n\t\tall(route, handler, opts) {\n\t\t\treturn this.on(\"\", route, handler, opts);\n\t\t}\n\t\t\"~findRoute\"(_event) {\n\t\t\treturn findRoute(this[\"~rou3\"], _event.req.method, _event.url.pathname);\n\t\t}\n\t\t\"~addRoute\"(_route) {\n\t\t\taddRoute(this[\"~rou3\"], _route.method, _route.route, _route);\n\t\t\tsuper[\"~addRoute\"](_route);\n\t\t}\n\t\tuse(arg1, arg2, arg3) {\n\t\t\tlet route;\n\t\t\tlet fn;\n\t\t\tlet opts;\n\t\t\tif (typeof arg1 === \"string\") {\n\t\t\t\troute = arg1;\n\t\t\t\tfn = arg2;\n\t\t\t\topts = arg3;\n\t\t\t} else {\n\t\t\t\tfn = arg1;\n\t\t\t\topts = arg2;\n\t\t\t}\n\t\t\tthis[\"~middleware\"].push(normalizeMiddleware(fn, {\n\t\t\t\t...opts,\n\t\t\t\troute\n\t\t\t}));\n\t\t\treturn this;\n\t\t}\n\t}\n\tfor (const method of [\n\t\t\"GET\",\n\t\t\"POST\",\n\t\t\"PUT\",\n\t\t\"DELETE\",\n\t\t\"PATCH\",\n\t\t\"HEAD\",\n\t\t\"OPTIONS\",\n\t\t\"CONNECT\",\n\t\t\"TRACE\"\n\t]) H3Core.prototype[method.toLowerCase()] = function(route, handler, opts) {\n\t\treturn this.on(method, route, handler, opts);\n\t};\n\treturn H3$1;\n})();\n\n\nfunction toWebHandler(app) {\n\treturn (request, context) => {\n\t\treturn Promise.resolve(app.request(request, void 0, context || request.context));\n\t};\n}\nfunction fromWebHandler(handler) {\n\treturn function _webHandler(event) {\n\t\treturn handler(event.req, event.context);\n\t};\n}\nfunction fromNodeHandler(handler) {\n\tif (typeof handler !== \"function\") throw new TypeError(`Invalid handler. It should be a function: ${handler}`);\n\treturn function _nodeHandler(event) {\n\t\tif (!event.runtime?.node?.res) throw new Error(\"[h3] Executing Node.js middleware is not supported in this server!\");\n\t\treturn callNodeHandler(handler, event.runtime?.node.req, event.runtime?.node.res);\n\t};\n}\nfunction defineNodeHandler(handler) {\n\treturn handler;\n}\nfunction defineNodeMiddleware(handler) {\n\treturn handler;\n}\nfunction callNodeHandler(handler, req, res) {\n\tconst isMiddleware = handler.length > 2;\n\treturn new Promise((resolve, reject) => {\n\t\tres.once(\"close\", () => resolve(kHandled));\n\t\tres.once(\"finish\", () => resolve(kHandled));\n\t\tres.once(\"pipe\", (stream) => resolve(stream));\n\t\tres.once(\"error\", (error) => reject(error));\n\t\ttry {\n\t\t\tif (isMiddleware) Promise.resolve(handler(req, res, (error) => error ? reject(new HTTPError({\n\t\t\t\tcause: error,\n\t\t\t\tunhandled: true\n\t\t\t})) : resolve(void 0))).catch((error) => reject(new HTTPError({\n\t\t\t\tcause: error,\n\t\t\t\tunhandled: true\n\t\t\t})));\n\t\t\telse return Promise.resolve(handler(req, res)).then(() => resolve(kHandled)).catch((error) => reject(new HTTPError({\n\t\t\t\tcause: error,\n\t\t\t\tunhandled: true\n\t\t\t})));\n\t\t} catch (error) {\n\t\t\treject(new HTTPError({\n\t\t\t\tcause: error,\n\t\t\t\tunhandled: true\n\t\t\t}));\n\t\t}\n\t});\n}\n\n\nfunction defineRoute(def) {\n\tconst handler = defineValidatedHandler(def);\n\treturn (h3) => {\n\t\th3.on(def.method, def.route, handler);\n\t};\n}\n\n\nconst textEncoder = /* @__PURE__ */ new TextEncoder();\nconst textDecoder = /* @__PURE__ */ new TextDecoder();\nconst base64Code = [\n\t65,\n\t66,\n\t67,\n\t68,\n\t69,\n\t70,\n\t71,\n\t72,\n\t73,\n\t74,\n\t75,\n\t76,\n\t77,\n\t78,\n\t79,\n\t80,\n\t81,\n\t82,\n\t83,\n\t84,\n\t85,\n\t86,\n\t87,\n\t88,\n\t89,\n\t90,\n\t97,\n\t98,\n\t99,\n\t100,\n\t101,\n\t102,\n\t103,\n\t104,\n\t105,\n\t106,\n\t107,\n\t108,\n\t109,\n\t110,\n\t111,\n\t112,\n\t113,\n\t114,\n\t115,\n\t116,\n\t117,\n\t118,\n\t119,\n\t120,\n\t121,\n\t122,\n\t48,\n\t49,\n\t50,\n\t51,\n\t52,\n\t53,\n\t54,\n\t55,\n\t56,\n\t57,\n\t45,\n\t95\n];\nfunction base64Encode(data) {\n\tconst buff = validateBinaryLike(data);\n\tif (globalThis.Buffer) return globalThis.Buffer.from(buff).toString(\"base64url\");\n\tconst bytes = [];\n\tlet i;\n\tconst len = buff.length;\n\tfor (i = 2; i < len; i += 3) bytes.push(base64Code[buff[i - 2] >> 2], base64Code[(buff[i - 2] & 3) << 4 | buff[i - 1] >> 4], base64Code[(buff[i - 1] & 15) << 2 | buff[i] >> 6], base64Code[buff[i] & 63]);\n\tif (i === len + 1) bytes.push(base64Code[buff[i - 2] >> 2], base64Code[(buff[i - 2] & 3) << 4]);\n\tif (i === len) bytes.push(base64Code[buff[i - 2] >> 2], base64Code[(buff[i - 2] & 3) << 4 | buff[i - 1] >> 4], base64Code[(buff[i - 1] & 15) << 2]);\n\treturn String.fromCharCode(...bytes);\n}\nfunction base64Decode(b64Url) {\n\tif (globalThis.Buffer) return new Uint8Array(globalThis.Buffer.from(b64Url, \"base64url\"));\n\tconst b64 = b64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\tconst binString = atob(b64);\n\tconst size = binString.length;\n\tconst bytes = new Uint8Array(size);\n\tfor (let i = 0; i < size; i++) bytes[i] = binString.charCodeAt(i);\n\treturn bytes;\n}\nfunction validateBinaryLike(source) {\n\tif (typeof source === \"string\") return textEncoder.encode(source);\n\telse if (source instanceof Uint8Array) return source;\n\telse if (source instanceof ArrayBuffer) return new Uint8Array(source);\n\tthrow new TypeError(`The input must be a Uint8Array, a string, or an ArrayBuffer.`);\n}\n\n\nfunction serializeIterableValue(value) {\n\tswitch (typeof value) {\n\t\tcase \"string\": return textEncoder.encode(value);\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"bigint\":\n\t\tcase \"symbol\": return textEncoder.encode(value.toString());\n\t\tcase \"object\":\n\t\t\tif (value instanceof Uint8Array) return value;\n\t\t\treturn textEncoder.encode(JSON.stringify(value));\n\t}\n\treturn new Uint8Array();\n}\nfunction coerceIterable(iterable$1) {\n\tif (typeof iterable$1 === \"function\") iterable$1 = iterable$1();\n\tif (Symbol.iterator in iterable$1) return iterable$1[Symbol.iterator]();\n\tif (Symbol.asyncIterator in iterable$1) return iterable$1[Symbol.asyncIterator]();\n\treturn iterable$1;\n}\n\n\nfunction noContent(status = 204) {\n\treturn new HTTPResponse(null, {\n\t\tstatus,\n\t\tstatusText: \"No Content\"\n\t});\n}\n\nfunction redirect(location, status = 302, statusText) {\n\treturn new HTTPResponse(`<html><head><meta http-equiv=\"refresh\" content=\"0; url=${location.replace(/\"/g, \"%22\")}\" /></head></html>`, {\n\t\tstatus,\n\t\tstatusText: statusText || (status === 301 ? \"Moved Permanently\" : \"Found\"),\n\t\theaders: {\n\t\t\t\"content-type\": \"text/html; charset=utf-8\",\n\t\t\tlocation