veloce-ts 0.2.3 → 0.2.4

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.
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{J as H}from"../../chunk-2100y16g.js";import{K as Jt,L as kt,M as qt}from"../../chunk-dtw2tbsd.js";import{N as Yt}from"../../chunk-vh4sxcpe.js";import"../../chunk-k66rn4fj.js";import{ja as Zt}from"../../chunk-mky5qqg0.js";import"../../chunk-yq3gf9ts.js";import"../../chunk-9v7atckx.js";import"../../chunk-5q75d71c.js";import{ta as $s,ua as bt,wa as Gt,xa as wt}from"../../chunk-y262e56g.js";var ot={};Gt(ot,{HonoAdapter:()=>Xt});class Xt{hono;name="hono";runtime;constructor(t){this.hono=t;this.runtime=Cs()}listen(t,s){switch(this.runtime){case"bun":return this.listenBun(t,s);case"deno":return this.listenDeno(t,s);case"node":return this.listenNode(t,s);case"workerd":throw Error("Cloudflare Workers do not support listen(). Deploy using wrangler or export the handler with getHandler().");default:throw Error(`Unsupported runtime: ${this.runtime}. FastAPI-TS supports Bun, Node.js, Deno, and Cloudflare Workers.`)}}getHandler(){return this.hono.fetch}getRuntime(){return this.runtime}listenBun(t,s){let i=Bun.serve({port:t,fetch:this.hono.fetch});if(s)s();return i}listenDeno(t,s){let i=new AbortController;return Deno.serve({port:t,signal:i.signal,onListen:s},this.hono.fetch),{port:t,close:()=>i.abort()}}listenNode(t,s){try{let{serve:i}=(()=>{throw new Error("Cannot require module "+"@hono/node-server");})();return i({fetch:this.hono.fetch,port:t},s)}catch(i){throw Error("Node.js adapter requires @hono/node-server package. Install it with: npm install @hono/node-server")}}}var Cs=()=>{if(typeof Bun<"u")return"bun";if(typeof Deno<"u")return"deno";if(typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers")return"workerd";if(typeof process<"u"&&process.versions&&process.versions.node)return"node";return"unknown"};var It={};Gt(It,{ExpressAdapter:()=>Vt});class Vt{app;name="express";express;constructor(t){this.app=t;try{let s=(()=>{throw new Error("Cannot require module "+"express");})();this.express=s(),this.setupBridge()}catch(s){throw Error("Express adapter requires express package. Install it with: npm install express")}}setupBridge(){let t=this.app.getHono();this.express.use(async(s,i)=>{try{let n=this.createWebRequest(s),f=await t.fetch(n);await this.sendExpressResponse(i,f)}catch(n){i.status(500).json({error:"Internal Server Error",message:n instanceof Error?n.message:"Unknown error"})}})}createWebRequest(t){let s=t.protocol||"http",i=t.get("host")||"localhost",n=`${s}://${i}${t.originalUrl||t.url}`,f=new Headers;for(let[h,e]of Object.entries(t.headers))if(typeof e==="string")f.set(h,e);else if(Array.isArray(e))e.forEach((c)=>f.append(h,c));let r={method:t.method,headers:f};if(t.method!=="GET"&&t.method!=="HEAD"){if(t.body)r.body=JSON.stringify(t.body),f.set("content-type","application/json")}return new Request(n,r)}async sendExpressResponse(t,s){if(t.status(s.status),s.headers.forEach((i,n)=>{t.setHeader(n,i)}),s.body){let i=s.headers.get("content-type")||"";if(i.includes("application/json")){let n=await s.json();t.json(n)}else if(i.includes("text/")){let n=await s.text();t.send(n)}else{let n=await s.arrayBuffer();t.send(Buffer.from(n))}}else t.end()}listen(t,s){return this.express.listen(t,s)}getHandler(){return this.express}getExpressApp(){return this.express}}class T{hono;constructor(t){this.hono=t.getHono()}async get(t,s){return this.request("GET",t,s)}async post(t,s){return this.request("POST",t,s)}async put(t,s){return this.request("PUT",t,s)}async delete(t,s){return this.request("DELETE",t,s)}async patch(t,s){return this.request("PATCH",t,s)}async request(t,s,i){let n=this.buildUrl(s,i?.query),f={method:t,headers:this.buildHeaders(i)};if(i?.body!==void 0)f.body=i.body;else if(i?.json!==void 0)f.body=JSON.stringify(i.json);let r=await this.hono.request(n,f),h=await r.text(),e;try{e=JSON.parse(h)}catch{e=h}return{status:r.status,headers:r.headers,body:e,text:h,json:async()=>JSON.parse(h),ok:r.ok}}buildUrl(t,s){if(!s||Object.keys(s).length===0)return t;let i=new URLSearchParams(s).toString();return`${t}?${i}`}buildHeaders(t){let s={...t?.headers};if(t?.json!==void 0&&!s["Content-Type"])s["Content-Type"]="application/json";return s}}var Z=(t,s,i)=>{return(n,f)=>{let r=-1;return h(0);async function h(e){if(e<=r)throw Error("next() called multiple times");r=e;let c,u=!1,w;if(t[e])w=t[e][0][0],n.req.routeIndex=e;else w=e===t.length&&f||void 0;if(w)try{c=await w(n,()=>h(e+1))}catch(y){if(y instanceof Error&&s)n.error=y,c=await s(y,n),u=!0;else throw y}else if(n.finalized===!1&&i)c=await i(n);if(c&&(n.finalized===!1||u))n.res=c;return n}}};var Ot=Symbol();var $t=async(t,s=Object.create(null))=>{let{all:i=!1,dot:n=!1}=s,r=(t instanceof z?t.raw.headers:t.headers).get("Content-Type");if(r?.startsWith("multipart/form-data")||r?.startsWith("application/x-www-form-urlencoded"))return ts(t,{all:i,dot:n});return{}};async function ts(t,s){let i=await t.formData();if(i)return ss(i,s);return{}}function ss(t,s){let i=Object.create(null);if(t.forEach((n,f)=>{if(!(s.all||f.endsWith("[]")))i[f]=n;else is(i,f,n)}),s.dot)Object.entries(i).forEach(([n,f])=>{if(n.includes("."))ns(i,n,f),delete i[n]});return i}var is=(t,s,i)=>{if(t[s]!==void 0)if(Array.isArray(t[s]))t[s].push(i);else t[s]=[t[s],i];else if(!s.endsWith("[]"))t[s]=i;else t[s]=[i]},ns=(t,s,i)=>{let n=t,f=s.split(".");f.forEach((r,h)=>{if(h===f.length-1)n[r]=i;else{if(!n[r]||typeof n[r]!=="object"||Array.isArray(n[r])||n[r]instanceof File)n[r]=Object.create(null);n=n[r]}})};var J=(t)=>{let s=t.split("/");if(s[0]==="")s.shift();return s},Ct=(t)=>{let{groups:s,path:i}=fs(t),n=J(i);return rs(n,s)},fs=(t)=>{let s=[];return t=t.replace(/\{[^}]+\}/g,(i,n)=>{let f=`@${n}`;return s.push([f,i]),f}),{groups:s,path:t}},rs=(t,s)=>{for(let i=s.length-1;i>=0;i--){let[n]=s[i];for(let f=t.length-1;f>=0;f--)if(t[f].includes(n)){t[f]=t[f].replace(n,s[i][1]);break}}return t},W={},Et=(t,s)=>{if(t==="*")return"*";let i=t.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(i){let n=`${t}#${s}`;if(!W[n])if(i[2])W[n]=s&&s[0]!==":"&&s[0]!=="*"?[n,i[1],new RegExp(`^${i[2]}(?=/${s})`)]:[t,i[1],new RegExp(`^${i[2]}$`)];else W[n]=[t,i[1],!0];return W[n]}return null},D=(t,s)=>{try{return s(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,(i)=>{try{return s(i)}catch{return i}})}},es=(t)=>D(t,decodeURI),k=(t)=>{let s=t.url,i=s.indexOf("/",s.indexOf(":")+4),n=i;for(;n<s.length;n++){let f=s.charCodeAt(n);if(f===37){let r=s.indexOf("?",n),h=s.slice(i,r===-1?void 0:r);return es(h.includes("%25")?h.replace(/%25/g,"%2525"):h)}else if(f===63)break}return s.slice(i,n)};var xt=(t)=>{let s=k(t);return s.length>1&&s.at(-1)==="/"?s.slice(0,-1):s},E=(t,s,...i)=>{if(i.length)s=E(s,...i);return`${t?.[0]==="/"?"":"/"}${t}${s==="/"?"":`${t?.at(-1)==="/"?"":"/"}${s?.[0]==="/"?s.slice(1):s}`}`},F=(t)=>{if(t.charCodeAt(t.length-1)!==63||!t.includes(":"))return null;let s=t.split("/"),i=[],n="";return s.forEach((f)=>{if(f!==""&&!/\:/.test(f))n+="/"+f;else if(/\:/.test(f))if(/\?/.test(f)){if(i.length===0&&n==="")i.push("/");else i.push(n);let r=f.replace("?","");n+="/"+r,i.push(n)}else n+="/"+f}),i.filter((f,r,h)=>h.indexOf(f)===r)},Y=(t)=>{if(!/[%+]/.test(t))return t;if(t.indexOf("+")!==-1)t=t.replace(/\+/g," ");return t.indexOf("%")!==-1?D(t,K):t},Ht=(t,s,i)=>{let n;if(!i&&s&&!/[%+]/.test(s)){let h=t.indexOf(`?${s}`,8);if(h===-1)h=t.indexOf(`&${s}`,8);while(h!==-1){let e=t.charCodeAt(h+s.length+1);if(e===61){let c=h+s.length+2,u=t.indexOf("&",c);return Y(t.slice(c,u===-1?void 0:u))}else if(e==38||isNaN(e))return"";h=t.indexOf(`&${s}`,h+1)}if(n=/[%+]/.test(t),!n)return}let f={};n??=/[%+]/.test(t);let r=t.indexOf("?",8);while(r!==-1){let h=t.indexOf("&",r+1),e=t.indexOf("=",r);if(e>h&&h!==-1)e=-1;let c=t.slice(r+1,e===-1?h===-1?void 0:h:e);if(n)c=Y(c);if(r=h,c==="")continue;let u;if(e===-1)u="";else if(u=t.slice(e+1,h===-1?void 0:h),n)u=Y(u);if(i){if(!(f[c]&&Array.isArray(f[c])))f[c]=[];f[c].push(u)}else f[c]??=u}return s?f[s]:f},jt=Ht,Dt=(t,s)=>{return Ht(t,s,!0)},K=decodeURIComponent;var lt=(t)=>D(t,K),z=class{raw;#s;#t;routeIndex=0;path;bodyCache={};constructor(t,s="/",i=[[]]){this.raw=t,this.path=s,this.#t=i,this.#s={}}param(t){return t?this.#i(t):this.#r()}#i(t){let s=this.#t[0][this.routeIndex][1][t],i=this.#f(s);return i&&/\%/.test(i)?lt(i):i}#r(){let t={},s=Object.keys(this.#t[0][this.routeIndex][1]);for(let i of s){let n=this.#f(this.#t[0][this.routeIndex][1][i]);if(n!==void 0)t[i]=/\%/.test(n)?lt(n):n}return t}#f(t){return this.#t[1]?this.#t[1][t]:t}query(t){return jt(this.url,t)}queries(t){return Dt(this.url,t)}header(t){if(t)return this.raw.headers.get(t)??void 0;let s={};return this.raw.headers.forEach((i,n)=>{s[n]=i}),s}async parseBody(t){return this.bodyCache.parsedBody??=await $t(this,t)}#n=(t)=>{let{bodyCache:s,raw:i}=this,n=s[t];if(n)return n;let f=Object.keys(s)[0];if(f)return s[f].then((r)=>{if(f==="json")r=JSON.stringify(r);return new Response(r)[t]()});return s[t]=i[t]()};json(){return this.#n("text").then((t)=>JSON.parse(t))}text(){return this.#n("text")}arrayBuffer(){return this.#n("arrayBuffer")}blob(){return this.#n("blob")}formData(){return this.#n("formData")}addValidatedData(t,s){this.#s[t]=s}valid(t){return this.#s[t]}get url(){return this.raw.url}get method(){return this.raw.method}get[Ot](){return this.#t}get matchedRoutes(){return this.#t[0].map(([[,t]])=>t)}get routePath(){return this.#t[0].map(([[,t]])=>t)[this.routeIndex].path}};var Nt={Stringify:1,BeforeStream:2,Stream:3},hs=(t,s)=>{let i=new String(t);return i.isEscaped=!0,i.callbacks=s,i};var q=async(t,s,i,n,f)=>{if(typeof t==="object"&&!(t instanceof String)){if(!(t instanceof Promise))t=t.toString();if(t instanceof Promise)t=await t}let r=t.callbacks;if(!r?.length)return Promise.resolve(t);if(f)f[0]+=t;else f=[t];let h=Promise.all(r.map((e)=>e({phase:s,buffer:f,context:n}))).then((e)=>Promise.all(e.filter(Boolean).map((c)=>q(c,s,!1,n,f))).then(()=>f[0]));if(i)return hs(await h,r);else return h};var cs="text/plain; charset=UTF-8",v=(t,s)=>{return{"Content-Type":t,...s}},Ut=class{#s;#t;env={};#i;finalized=!1;error;#r;#f;#n;#w;#c;#u;#h;#y;#g;constructor(t,s){if(this.#s=t,s)this.#f=s.executionCtx,this.env=s.env,this.#u=s.notFoundHandler,this.#g=s.path,this.#y=s.matchResult}get req(){return this.#t??=new z(this.#s,this.#g,this.#y),this.#t}get event(){if(this.#f&&"respondWith"in this.#f)return this.#f;else throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#f)return this.#f;else throw Error("This context has no ExecutionContext")}get res(){return this.#n||=new Response(null,{headers:this.#h??=new Headers})}set res(t){if(this.#n&&t){t=new Response(t.body,t);for(let[s,i]of this.#n.headers.entries()){if(s==="content-type")continue;if(s==="set-cookie"){let n=this.#n.headers.getSetCookie();t.headers.delete("set-cookie");for(let f of n)t.headers.append("set-cookie",f)}else t.headers.set(s,i)}}this.#n=t,this.finalized=!0}render=(...t)=>{return this.#c??=(s)=>this.html(s),this.#c(...t)};setLayout=(t)=>this.#w=t;getLayout=()=>this.#w;setRenderer=(t)=>{this.#c=t};header=(t,s,i)=>{if(this.finalized)this.#n=new Response(this.#n.body,this.#n);let n=this.#n?this.#n.headers:this.#h??=new Headers;if(s===void 0)n.delete(t);else if(i?.append)n.append(t,s);else n.set(t,s)};status=(t)=>{this.#r=t};set=(t,s)=>{this.#i??=new Map,this.#i.set(t,s)};get=(t)=>{return this.#i?this.#i.get(t):void 0};get var(){if(!this.#i)return{};return Object.fromEntries(this.#i)}#e(t,s,i){let n=this.#n?new Headers(this.#n.headers):this.#h??new Headers;if(typeof s==="object"&&"headers"in s){let r=s.headers instanceof Headers?s.headers:new Headers(s.headers);for(let[h,e]of r)if(h.toLowerCase()==="set-cookie")n.append(h,e);else n.set(h,e)}if(i)for(let[r,h]of Object.entries(i))if(typeof h==="string")n.set(r,h);else{n.delete(r);for(let e of h)n.append(r,e)}let f=typeof s==="number"?s:s?.status??this.#r;return new Response(t,{status:f,headers:n})}newResponse=(...t)=>this.#e(...t);body=(t,s,i)=>this.#e(t,s,i);text=(t,s,i)=>{return!this.#h&&!this.#r&&!s&&!i&&!this.finalized?new Response(t):this.#e(t,s,v(cs,i))};json=(t,s,i)=>{return this.#e(JSON.stringify(t),s,v("application/json",i))};html=(t,s,i)=>{let n=(f)=>this.#e(f,s,v("text/html; charset=UTF-8",i));return typeof t==="object"?q(t,Nt.Stringify,!1,{}).then(n):n(t)};redirect=(t,s)=>{let i=String(t);return this.header("Location",!/[^\x00-\xFF]/.test(i)?i:encodeURI(i)),this.newResponse(null,s??302)};notFound=()=>{return this.#u??=()=>new Response,this.#u(this)}};var g="ALL",Kt="all",At=["get","post","put","delete","options","patch"],B="Can not add a route since the matcher is already built.",Q=class extends Error{};var Lt="__COMPOSED_HANDLER";var us=(t)=>{return t.text("404 Not Found",404)},Rt=(t,s)=>{if("getResponse"in t){let i=t.getResponse();return s.newResponse(i.body,i)}return console.error(t),s.text("Internal Server Error",500)},M=class{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#s="/";routes=[];constructor(t={}){[...At,Kt].forEach((f)=>{this[f]=(r,...h)=>{if(typeof r==="string")this.#s=r;else this.#r(f,this.#s,r);return h.forEach((e)=>{this.#r(f,this.#s,e)}),this}}),this.on=(f,r,...h)=>{for(let e of[r].flat()){this.#s=e;for(let c of[f].flat())h.map((u)=>{this.#r(c.toUpperCase(),this.#s,u)})}return this},this.use=(f,...r)=>{if(typeof f==="string")this.#s=f;else this.#s="*",r.unshift(f);return r.forEach((h)=>{this.#r(g,this.#s,h)}),this};let{strict:i,...n}=t;Object.assign(this,n),this.getPath=i??!0?t.getPath??k:xt}#t(){let t=new M({router:this.router,getPath:this.getPath});return t.errorHandler=this.errorHandler,t.#i=this.#i,t.routes=this.routes,t}#i=us;errorHandler=Rt;route(t,s){let i=this.basePath(t);return s.routes.map((n)=>{let f;if(s.errorHandler===Rt)f=n.handler;else f=async(r,h)=>(await Z([],s.errorHandler)(r,()=>n.handler(r,h))).res,f[Lt]=n.handler;i.#r(n.method,n.path,f)}),this}basePath(t){let s=this.#t();return s._basePath=E(this._basePath,t),s}onError=(t)=>{return this.errorHandler=t,this};notFound=(t)=>{return this.#i=t,this};mount(t,s,i){let n,f;if(i)if(typeof i==="function")f=i;else if(f=i.optionHandler,i.replaceRequest===!1)n=(e)=>e;else n=i.replaceRequest;let r=f?(e)=>{let c=f(e);return Array.isArray(c)?c:[c]}:(e)=>{let c=void 0;try{c=e.executionCtx}catch{}return[e.env,c]};n||=(()=>{let e=E(this._basePath,t),c=e==="/"?0:e.length;return(u)=>{let w=new URL(u.url);return w.pathname=w.pathname.slice(c)||"/",new Request(w,u)}})();let h=async(e,c)=>{let u=await s(n(e.req.raw),...r(e));if(u)return u;await c()};return this.#r(g,E(t,"*"),h),this}#r(t,s,i){t=t.toUpperCase(),s=E(this._basePath,s);let n={basePath:this._basePath,path:s,method:t,handler:i};this.router.add(t,s,[i,n]),this.routes.push(n)}#f(t,s){if(t instanceof Error)return this.errorHandler(t,s);throw t}#n(t,s,i,n){if(n==="HEAD")return(async()=>new Response(null,await this.#n(t,s,i,"GET")))();let f=this.getPath(t,{env:i}),r=this.router.match(n,f),h=new Ut(t,{path:f,matchResult:r,env:i,executionCtx:s,notFoundHandler:this.#i});if(r[0].length===1){let c;try{c=r[0][0][0][0](h,async()=>{h.res=await this.#i(h)})}catch(u){return this.#f(u,h)}return c instanceof Promise?c.then((u)=>u||(h.finalized?h.res:this.#i(h))).catch((u)=>this.#f(u,h)):c??this.#i(h)}let e=Z(r[0],this.errorHandler,this.#i);return(async()=>{try{let c=await e(h);if(!c.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return c.res}catch(c){return this.#f(c,h)}})()}fetch=(t,...s)=>{return this.#n(t,s[1],s[0],t.method)};request=(t,s,i,n)=>{if(t instanceof Request)return this.fetch(s?new Request(t,s):t,i,n);return t=t.toString(),this.fetch(new Request(/^https?:\/\//.test(t)?t:`http://localhost${E("/",t)}`,s),i,n)};fire=()=>{addEventListener("fetch",(t)=>{t.respondWith(this.#n(t.request,t,void 0,t.request.method))})}};var G="[^/]+",A=".*",L="(?:|/.*)",x=Symbol(),ws=new Set(".\\+*[^]$()");function ys(t,s){if(t.length===1)return s.length===1?t<s?-1:1:-1;if(s.length===1)return 1;if(t===A||t===L)return 1;else if(s===A||s===L)return-1;if(t===G)return 1;else if(s===G)return-1;return t.length===s.length?t<s?-1:1:s.length-t.length}var X=class{#s;#t;#i=Object.create(null);insert(t,s,i,n,f){if(t.length===0){if(this.#s!==void 0)throw x;if(f)return;this.#s=s;return}let[r,...h]=t,e=r==="*"?h.length===0?["","",A]:["","",G]:r==="/*"?["","",L]:r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(e){let u=e[1],w=e[2]||G;if(u&&e[2]){if(w===".*")throw x;if(w=w.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(w))throw x}if(c=this.#i[w],!c){if(Object.keys(this.#i).some((y)=>y!==A&&y!==L))throw x;if(f)return;if(c=this.#i[w]=new X,u!=="")c.#t=n.varIndex++}if(!f&&u!=="")i.push([u,c.#t])}else if(c=this.#i[r],!c){if(Object.keys(this.#i).some((u)=>u.length>1&&u!==A&&u!==L))throw x;if(f)return;c=this.#i[r]=new X}c.insert(h,s,i,n,f)}buildRegExpStr(){let s=Object.keys(this.#i).sort(ys).map((i)=>{let n=this.#i[i];return(typeof n.#t==="number"?`(${i})@${n.#t}`:ws.has(i)?`\\${i}`:i)+n.buildRegExpStr()});if(typeof this.#s==="number")s.unshift(`#${this.#s}`);if(s.length===0)return"";if(s.length===1)return s[0];return"(?:"+s.join("|")+")"}};var Tt=class{#s={varIndex:0};#t=new X;insert(t,s,i){let n=[],f=[];for(let h=0;;){let e=!1;if(t=t.replace(/\{[^}]+\}/g,(c)=>{let u=`@\\${h}`;return f[h]=[u,c],h++,e=!0,u}),!e)break}let r=t.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let h=f.length-1;h>=0;h--){let[e]=f[h];for(let c=r.length-1;c>=0;c--)if(r[c].indexOf(e)!==-1){r[c]=r[c].replace(e,f[h][1]);break}}return this.#t.insert(r,s,n,this.#s,i),n}buildRegExp(){let t=this.#t.buildRegExpStr();if(t==="")return[/^$/,[],[]];let s=0,i=[],n=[];return t=t.replace(/#(\d+)|@(\d+)|\.\*\$/g,(f,r,h)=>{if(r!==void 0)return i[++s]=Number(r),"$()";if(h!==void 0)return n[Number(h)]=++s,"";return""}),[new RegExp(`^${t}`),i,n]}};var zt=[],gs=[/^$/,[],Object.create(null)],Wt=Object.create(null);function Ft(t){return Wt[t]??=new RegExp(t==="*"?"":`^${t.replace(/\/\*$|([.\\+*[^\]$()])/g,(s,i)=>i?`\\${i}`:"(?:|/.*)")}$`)}function Ps(){Wt=Object.create(null)}function os(t){let s=new Tt,i=[];if(t.length===0)return gs;let n=t.map((u)=>[!/\*|\/:/.test(u[0]),...u]).sort(([u,w],[y,o])=>u?1:y?-1:w.length-o.length),f=Object.create(null);for(let u=0,w=-1,y=n.length;u<y;u++){let[o,S,P]=n[u];if(o)f[S]=[P.map(([_])=>[_,Object.create(null)]),zt];else w++;let b;try{b=s.insert(S,w,o)}catch(_){throw _===x?new Q(S):_}if(o)continue;i[w]=P.map(([_,j])=>{let N=Object.create(null);j-=1;for(;j>=0;j--){let[O,I]=b[j];N[O]=I}return[_,N]})}let[r,h,e]=s.buildRegExp();for(let u=0,w=i.length;u<w;u++)for(let y=0,o=i[u].length;y<o;y++){let S=i[u][y]?.[1];if(!S)continue;let P=Object.keys(S);for(let b=0,_=P.length;b<_;b++)S[P[b]]=e[S[P[b]]]}let c=[];for(let u in h)c[u]=i[h[u]];return[r,c,f]}function l(t,s){if(!t)return;for(let i of Object.keys(t).sort((n,f)=>f.length-n.length))if(Ft(i).test(s))return[...t[i]];return}var d=class{name="RegExpRouter";#s;#t;constructor(){this.#s={[g]:Object.create(null)},this.#t={[g]:Object.create(null)}}add(t,s,i){let n=this.#s,f=this.#t;if(!n||!f)throw Error(B);if(!n[t])[n,f].forEach((e)=>{e[t]=Object.create(null),Object.keys(e[g]).forEach((c)=>{e[t][c]=[...e[g][c]]})});if(s==="/*")s="*";let r=(s.match(/\/:/g)||[]).length;if(/\*$/.test(s)){let e=Ft(s);if(t===g)Object.keys(n).forEach((c)=>{n[c][s]||=l(n[c],s)||l(n[g],s)||[]});else n[t][s]||=l(n[t],s)||l(n[g],s)||[];Object.keys(n).forEach((c)=>{if(t===g||t===c)Object.keys(n[c]).forEach((u)=>{e.test(u)&&n[c][u].push([i,r])})}),Object.keys(f).forEach((c)=>{if(t===g||t===c)Object.keys(f[c]).forEach((u)=>e.test(u)&&f[c][u].push([i,r]))});return}let h=F(s)||[s];for(let e=0,c=h.length;e<c;e++){let u=h[e];Object.keys(f).forEach((w)=>{if(t===g||t===w)f[w][u]||=[...l(n[w],u)||l(n[g],u)||[]],f[w][u].push([i,r-c+e+1])})}}match(t,s){Ps();let i=this.#i();return this.match=(n,f)=>{let r=i[n]||i[g],h=r[2][f];if(h)return h;let e=f.match(r[0]);if(!e)return[[],zt];let c=e.indexOf("",1);return[r[1][c],e]},this.match(t,s)}#i(){let t=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#s)).forEach((s)=>{t[s]||=this.#r(s)}),this.#s=this.#t=void 0,t}#r(t){let s=[],i=t===g;if([this.#s,this.#t].forEach((n)=>{let f=n[t]?Object.keys(n[t]).map((r)=>[r,n[t][r]]):[];if(f.length!==0)i||=!0,s.push(...f);else if(t!==g)s.push(...Object.keys(n[g]).map((r)=>[r,n[g][r]]))}),!i)return null;else return os(s)}};var m=class{name="SmartRouter";#s=[];#t=[];constructor(t){this.#s=t.routers}add(t,s,i){if(!this.#t)throw Error(B);this.#t.push([t,s,i])}match(t,s){if(!this.#t)throw Error("Fatal error");let i=this.#s,n=this.#t,f=i.length,r=0,h;for(;r<f;r++){let e=i[r];try{for(let c=0,u=n.length;c<u;c++)e.add(...n[c]);h=e.match(t,s)}catch(c){if(c instanceof Q)continue;throw c}this.match=e.match.bind(e),this.#s=[e],this.#t=void 0;break}if(r===f)throw Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,h}get activeRouter(){if(this.#t||this.#s.length!==1)throw Error("No active router has been determined yet.");return this.#s[0]}};var R=Object.create(null),a=class{#s;#t;#i;#r=0;#f=R;constructor(t,s,i){if(this.#t=i||Object.create(null),this.#s=[],t&&s){let n=Object.create(null);n[t]={handler:s,possibleKeys:[],score:0},this.#s=[n]}this.#i=[]}insert(t,s,i){this.#r=++this.#r;let n=this,f=Ct(s),r=[];for(let h=0,e=f.length;h<e;h++){let c=f[h],u=f[h+1],w=Et(c,u),y=Array.isArray(w)?w[0]:c;if(y in n.#t){if(n=n.#t[y],w)r.push(w[1]);continue}if(n.#t[y]=new a,w)n.#i.push(w),r.push(w[1]);n=n.#t[y]}return n.#s.push({[t]:{handler:i,possibleKeys:r.filter((h,e,c)=>c.indexOf(h)===e),score:this.#r}}),n}#n(t,s,i,n){let f=[];for(let r=0,h=t.#s.length;r<h;r++){let e=t.#s[r],c=e[s]||e[g],u={};if(c!==void 0){if(c.params=Object.create(null),f.push(c),i!==R||n&&n!==R)for(let w=0,y=c.possibleKeys.length;w<y;w++){let o=c.possibleKeys[w],S=u[c.score];c.params[o]=n?.[o]&&!S?n[o]:i[o]??n?.[o],u[c.score]=!0}}}return f}search(t,s){let i=[];this.#f=R;let f=[this],r=J(s),h=[];for(let e=0,c=r.length;e<c;e++){let u=r[e],w=e===c-1,y=[];for(let o=0,S=f.length;o<S;o++){let P=f[o],b=P.#t[u];if(b)if(b.#f=P.#f,w){if(b.#t["*"])i.push(...this.#n(b.#t["*"],t,P.#f));i.push(...this.#n(b,t,P.#f))}else y.push(b);for(let _=0,j=P.#i.length;_<j;_++){let N=P.#i[_],O=P.#f===R?{}:{...P.#f};if(N==="*"){let C=P.#t["*"];if(C)i.push(...this.#n(C,t,P.#f)),C.#f=O,y.push(C);continue}let[I,_t,U]=N;if(!u&&!(U instanceof RegExp))continue;let $=P.#t[I],at=r.slice(e).join("/");if(U instanceof RegExp){let C=U.exec(at);if(C){if(O[_t]=C[0],i.push(...this.#n($,t,P.#f,O)),Object.keys($.#t).length){$.#f=O;let pt=C[0].match(/\//)?.length??0;(h[pt]||=[]).push($)}continue}}if(U===!0||U.test(u))if(O[_t]=u,w){if(i.push(...this.#n($,t,O,P.#f)),$.#t["*"])i.push(...this.#n($.#t["*"],t,O,P.#f))}else $.#f=O,y.push($)}}f=y.concat(h.shift()??[])}if(i.length>1)i.sort((e,c)=>{return e.score-c.score});return[i.map(({handler:e,params:c})=>[e,c])]}};var p=class{name="TrieRouter";#s;constructor(){this.#s=new a}add(t,s,i){let n=F(s);if(n){for(let f=0,r=n.length;f<r;f++)this.#s.insert(t,n[f],i);return}this.#s.insert(t,s,i)}match(t,s){return this.#s.search(t,s)}};var tt=class extends M{constructor(t={}){super(t);this.router=t.router??new m({routers:[new d,new p]})}};class st{singletons=new Map;requestScoped=new WeakMap;providers=new Map;resolutionStack=new Set;providerNameCache=new WeakMap;stats={singletonHits:0,singletonMisses:0,requestHits:0,requestMisses:0,transientCreations:0};register(t,s){this.providers.set(t,s||{scope:"transient"})}async resolve(t,s){let i=this.providers.get(t)||{scope:s?.scope||"transient"},n=s?.scope||i.scope||"transient";if(n==="singleton"){if(this.singletons.has(t))return this.stats.singletonHits++,this.singletons.get(t);if(this.stats.singletonMisses++,this.resolutionStack.has(t))throw Error(`Circular dependency detected: ${this.buildCircularDependencyMessage(t)}`);this.resolutionStack.add(t);try{let f=await this.create(t,i,s?.context);return this.singletons.set(t,f),f}finally{this.resolutionStack.delete(t)}}if(n==="request"&&s?.context){let f=this.requestScoped.get(s.context);if(f?.has(t))return this.stats.requestHits++,f.get(t);if(this.stats.requestMisses++,!f)f=new Map,this.requestScoped.set(s.context,f);if(this.resolutionStack.has(t))throw Error(`Circular dependency detected: ${this.buildCircularDependencyMessage(t)}`);this.resolutionStack.add(t);try{let r=await this.create(t,i,s.context);return f.set(t,r),r}finally{this.resolutionStack.delete(t)}}if(this.stats.transientCreations++,this.resolutionStack.has(t))throw Error(`Circular dependency detected: ${this.buildCircularDependencyMessage(t)}`);this.resolutionStack.add(t);try{return await this.create(t,i,s?.context)}finally{this.resolutionStack.delete(t)}}buildCircularDependencyMessage(t){let s=Array.from(this.resolutionStack),i=this.getProviderName(t);return s.map((f)=>this.getProviderName(f)).join(" -> ")+" -> "+i}async create(t,s,i){if(s.factory)return s.factory();if(typeof t==="function")if(t.prototype&&t.prototype.constructor===t){let n=new t;return await this.resolveNestedDependencies(n,i),n}else{let n=t();return n instanceof Promise?await n:n}throw Error("Invalid provider type")}async resolveNestedDependencies(t,s){}getProviderName(t){let s=this.providerNameCache.get(t);if(s)return s;let i;if(typeof t==="function")if(t.name)i=t.name;else i=t.toString().substring(0,50);else i=String(t);return this.providerNameCache.set(t,i),i}clear(){this.singletons.clear(),this.providers.clear(),this.resolutionStack.clear(),this.providerNameCache=new WeakMap,this.resetStats()}clearRequestScope(t){this.requestScoped.delete(t)}getStats(){let t=this.stats.singletonHits+this.stats.singletonMisses,s=t>0?this.stats.singletonHits/t*100:0,i=this.stats.requestHits+this.stats.requestMisses,n=i>0?this.stats.requestHits/i*100:0;return{singletonHits:this.stats.singletonHits,singletonMisses:this.stats.singletonMisses,singletonHitRate:Math.round(s*100)/100,requestHits:this.stats.requestHits,requestMisses:this.stats.requestMisses,requestHitRate:Math.round(n*100)/100,transientCreations:this.stats.transientCreations}}resetStats(){this.stats={singletonHits:0,singletonMisses:0,requestHits:0,requestMisses:0,transientCreations:0}}}var bs=/^[\w!#$%&'*.^`|~+-]+$/,Ss=/^[ !#-:<-[\]-~]*$/,it=(t,s)=>{if(s&&t.indexOf(s)===-1)return{};let i=t.trim().split(";"),n={};for(let f of i){f=f.trim();let r=f.indexOf("=");if(r===-1)continue;let h=f.substring(0,r).trim();if(s&&s!==h||!bs.test(h))continue;let e=f.substring(r+1).trim();if(e.startsWith('"')&&e.endsWith('"'))e=e.slice(1,-1);if(Ss.test(e)){if(n[h]=e.indexOf("%")!==-1?D(e,K):e,s)break}}return n};var _s=(t,s,i={})=>{let n=`${t}=${s}`;if(t.startsWith("__Secure-")&&!i.secure)throw Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!i.secure)throw Error("__Host- Cookie must have Secure attributes");if(i.path!=="/")throw Error('__Host- Cookie must have Path attributes with "/"');if(i.domain)throw Error("__Host- Cookie must not have Domain attributes")}if(i&&typeof i.maxAge==="number"&&i.maxAge>=0){if(i.maxAge>34560000)throw Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");n+=`; Max-Age=${i.maxAge|0}`}if(i.domain&&i.prefix!=="host")n+=`; Domain=${i.domain}`;if(i.path)n+=`; Path=${i.path}`;if(i.expires){if(i.expires.getTime()-Date.now()>34560000000)throw Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");n+=`; Expires=${i.expires.toUTCString()}`}if(i.httpOnly)n+="; HttpOnly";if(i.secure)n+="; Secure";if(i.sameSite)n+=`; SameSite=${i.sameSite.charAt(0).toUpperCase()+i.sameSite.slice(1)}`;if(i.priority)n+=`; Priority=${i.priority.charAt(0).toUpperCase()+i.priority.slice(1)}`;if(i.partitioned){if(!i.secure)throw Error("Partitioned Cookie must have Secure attributes");n+="; Partitioned"}return n},V=(t,s,i)=>{return s=encodeURIComponent(s),_s(t,s,i)};var Bt=(t,s,i)=>{let n=t.req.raw.headers.get("Cookie");if(typeof s==="string"){if(!n)return;let r=s;if(i==="secure")r="__Secure-"+s;else if(i==="host")r="__Host-"+s;return it(n,r)[r]}if(!n)return{};return it(n)};var Os=(t,s,i)=>{let n;if(i?.prefix==="secure")n=V("__Secure-"+t,s,{path:"/",...i,secure:!0});else if(i?.prefix==="host")n=V("__Host-"+t,s,{...i,path:"/",secure:!0,domain:void 0});else n=V(t,s,{path:"/",...i});return n},Gi=(t,s,i,n)=>{let f=Os(s,i,n);t.header("Set-Cookie",f,{append:!0})};class Qt{static json(t,s=200,i){return new nt(t,s,i)}static html(t,s=200){return new ft(t,s)}static file(t,s){return new et(t,s)}static stream(t,s){return new ht(t,s)}static redirect(t,s=302){return new rt(t,s)}}class nt{data;status;headers;constructor(t,s=200,i={}){this.data=t;this.status=s;this.headers=i}toHonoResponse(t){return t.json(this.data,this.status,this.headers)}}class ft{content;status;constructor(t,s=200){this.content=t;this.status=s}toHonoResponse(t){return t.html(this.content,this.status)}}class rt{url;status;constructor(t,s=302){this.url=t;this.status=s}toHonoResponse(t){return t.redirect(this.url,this.status)}}class et{path;options;constructor(t,s){this.path=t;this.options=s}async toHonoResponse(t){try{let s=typeof Bun<"u"?Bun.file(this.path):await this.readFileNode(this.path),n={"Content-Type":this.options?.contentType||this.guessContentType(this.path)};if(this.options?.download||this.options?.filename){let f=this.options?.filename||this.path.split("/").pop()||"download",r=this.options?.download?"attachment":"inline";n["Content-Disposition"]=`${r}; filename="${f}"`}if(typeof Bun<"u"&&s instanceof Blob)return t.body(s,200,n);else return t.body(s,200,n)}catch(s){return t.json({error:"File not found",message:s instanceof Error?s.message:"Unknown error"},404)}}async readFileNode(t){throw Error("File reading in Node.js requires fs module - use Bun runtime or implement adapter")}guessContentType(t){let s=t.split(".").pop()?.toLowerCase();return{html:"text/html",css:"text/css",js:"application/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",svg:"image/svg+xml",pdf:"application/pdf",txt:"text/plain",xml:"application/xml"}[s||""]||"application/octet-stream"}}class ht{stream;options;constructor(t,s){this.stream=t;this.options=s}toHonoResponse(t){let s={"Content-Type":this.options?.contentType||"application/octet-stream",...this.options?.headers};return t.body(this.stream,200,s)}}class ct{static serialize(t,s){if(s===null||s===void 0)return t.body(null,204);if(s instanceof Qt)return s;if(s instanceof nt)return s.toHonoResponse(t);if(s instanceof ft)return s.toHonoResponse(t);if(s instanceof et)return s.toHonoResponse(t);if(s instanceof ht)return s.toHonoResponse(t);if(s instanceof rt)return s.toHonoResponse(t);if(s&&typeof s.toHonoResponse==="function")return s.toHonoResponse(t);return t.json(s)}}class ut{static compile(t){let s=this.compilePathRegex(t.path),i=this.resolveParameterOrder(t.parameters),n=this.resolveDependencyOrder(t.dependencies),f=this.calculateMaxArgumentIndex(t.parameters,t.dependencies),r=this.computeParameterFlags(t.parameters);return{...t,pathRegex:s,parameterOrder:i,dependencyOrder:n,maxArgumentIndex:f,...r}}static compilePathRegex(t){let s=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return s=s.replace(/\\\{([^}]+)\\\}/g,"(?<$1>[^/]+)"),s=s.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"(?<$1>[^/]+)"),s=`^${s}$`,new RegExp(s)}static resolveParameterOrder(t){if(!t||t.length===0)return[];return t.map((s)=>s.index).filter((s)=>s!==void 0).sort((s,i)=>s-i)}static resolveDependencyOrder(t){if(!t||t.length===0)return[];return t.map((s)=>s.index).filter((s)=>s!==void 0).sort((s,i)=>s-i)}static calculateMaxArgumentIndex(t,s){let i=-1;if(t&&t.length>0){let n=Math.max(...t.map((f)=>f.index));i=Math.max(i,n)}if(s&&s.length>0){let n=Math.max(...s.map((f)=>f.index));i=Math.max(i,n)}return i}static computeParameterFlags(t){if(!t||t.length===0)return{hasBody:!1,hasQuery:!1,hasParams:!1,hasHeaders:!1,hasCookies:!1,hasDependencies:!1};return{hasBody:t.some((s)=>s.type==="body"),hasQuery:t.some((s)=>s.type==="query"),hasParams:t.some((s)=>s.type==="param"),hasHeaders:t.some((s)=>s.type==="header"),hasCookies:t.some((s)=>s.type==="cookie"),hasDependencies:!1}}static compileAll(t){return t.map((s)=>this.compile(s))}}class yt{app;metadata;container;validator;errorHandler;compiledRoutes=new Map;constructor(t,s,i,n,f){this.app=t;this.metadata=s;this.container=i;this.validator=n;this.errorHandler=f}compile(){let t=this.metadata.getRoutes(),s=ut.compileAll(t);for(let i of s){let n=`${i.target.name}:${i.propertyKey}`;this.compiledRoutes.set(n,i);let f=this.createHandler(i),r=this.normalizePath(i.path),h=i.method.toLowerCase();if(i.middleware&&i.middleware.length>0)this.app[h](r,...i.middleware,f);else this.app[h](r,f)}}normalizePath(t){if(!t.startsWith("/"))t="/"+t;if(t=t.replace(/\{([^}]+)\}/g,":$1"),t.length>1&&t.endsWith("/"))t=t.slice(0,-1);return t}createHandler(t){return async(s)=>{try{s.set("routeMetadata",t);let i=await this.extractParameters(s,t.parameters),n=await this.resolveDependencies(s,t.dependencies),f=this.mergeArguments(i,n,t.parameters,t.maxArgumentIndex),r;if(t.handler)r=await t.handler(s,...f);else{let h=await this.container.resolve(t.target,{scope:"transient",context:s});if(typeof h[t.propertyKey]!=="function")throw Error(`Method ${t.propertyKey} not found on controller ${t.target.name}`);r=await h[t.propertyKey](...f)}return this.serializeResponse(s,r)}catch(i){return await this.handleError(s,i)}}}serializeResponse(t,s){return ct.serialize(t,s)}getRouteMetadataForContext(t){return t.get("routeMetadata")||null}isAuthRequired(t){if(t.auth?.required)return!0;return t.parameters.some((s)=>s.type==="current-user")}async handleError(t,s){return await this.errorHandler.handle(s,t)}async extractParameters(t,s){let i=[];for(let n of s){if(!n)continue;let f;switch(n.type){case"body":try{f=await t.req.json()}catch(e){f=null}break;case"query":if(n.name)f=t.req.query(n.name);else f=t.req.query();break;case"param":if(n.name)f=t.req.param(n.name);else f=t.req.param();break;case"header":if(n.name)f=t.req.header(n.name);else{let e={};t.req.raw.headers.forEach((c,u)=>{e[u]=c}),f=e}break;case"cookie":if(n.name)f=Bt(t,n.name);else{let e=t.req.header("cookie");if(e)f=Object.fromEntries(e.split(";").map((c)=>{let[u,...w]=c.trim().split("=");return[u,w.join("=")]}));else f={}}break;case"request":f=t.req;break;case"response":case"context":f=t;break;case"current-user":f=t.get("auth.user")||null;let r=this.getRouteMetadataForContext(t);if(r&&this.isAuthRequired(r)){if(!f){let e=t.get("auth.error")||"Authentication required",{AuthenticationException:c}=await import("../../chunk-s5z0wb7e.js");throw new c(e)}}break;case"token":f=t.get("auth.token")||null;break;case"oauth-user":f=t.get("oauth.user")||null;break;case"oauth-token":f=t.get("oauth.token")||null;break;case"current-session":f=t.get("session")||null;break;case"session-data":let h=t.get("session");if(h&&n.metadata?.key)f=h.data[n.metadata.key];else if(h)f=h.data;else f=null;break;case"csrf-token":f=t.get("csrf.token")||null;break;case"filtered-resource":f=t.get("filtered.resource")||null;break;case"filtered-attributes":f=t.get("filtered.attributes")||[];break;default:f=void 0}if(n.schema)try{f=await this.validator.validate(f,n.schema)}catch(r){throw r}i[n.index]=f}return i}mergeArguments(t,s,i,n){let r=i.filter((u)=>u!==void 0&&u.index!==void 0).map((u)=>u.index),h=r.length>0?Math.max(...r):-1,e=n!==void 0&&n>=0?n:Math.max(h,t.length-1,s.length-1,0);if(!Number.isFinite(e)||e<0)e=0;let c=Array(e+1);for(let u=0;u<=e;u++)if(t[u]!==void 0)c[u]=t[u];else if(s[u]!==void 0)c[u]=s[u];return c}async resolveDependencies(t,s){let i=[];for(let n of s){if(!n)continue;try{let f=await this.container.resolve(n.provider,{scope:n.scope,context:t});i[n.index]=f}catch(f){throw Error(`Failed to resolve dependency at index ${n.index}: ${f instanceof Error?f.message:"Unknown error"}`)}}return i}}class gt{plugins=new Map;installed=new Set;register(t){if(this.plugins.has(t.name))throw Error(`Plugin "${t.name}" is already registered`);this.plugins.set(t.name,t)}async install(t){let s=this.resolveInstallOrder();for(let i of s)await this.plugins.get(i).install(t),this.installed.add(i)}isInstalled(t){return this.installed.has(t)}getPlugin(t){return this.plugins.get(t)}getPluginNames(){return Array.from(this.plugins.keys())}resolveInstallOrder(){let t=new Set,s=new Set,i=[],n=(f,r=[])=>{if(s.has(f)){let e=[...r,f].join(" -> ");throw Error(`Circular dependency detected in plugins: ${e}`)}if(t.has(f))return;s.add(f);let h=this.plugins.get(f);if(!h)throw Error(`Plugin "${f}" is not registered`);if(h.dependencies)for(let e of h.dependencies){if(!this.plugins.has(e))throw Error(`Plugin "${f}" depends on "${e}" which is not registered`);n(e,[...r,f])}s.delete(f),t.add(f),i.push(f)};for(let f of this.plugins.keys())n(f);return i}}class St{hono;metadata;container;validator;errorHandler;compiler;pluginManager;config;compiled=!1;globalMiddleware=[];groupPrefix="";constructor(t){if(this.config={adapter:"hono",title:"Veloce-TS API",version:"1.0.0",docs:!0,...t},this.hono=new tt,this.metadata=new H,this.container=new st,this.validator=new Zt,this.errorHandler=new Yt,this.pluginManager=new gt,this.compiler=new yt(this.hono,this.metadata,this.container,this.validator,this.errorHandler),this.config.cors)if(this.config.cors===!0)this.useCors();else this.useCors(this.config.cors)}include(t){let s=H.getControllerMetadata(t);if(s)this.metadata.registerController(t,s);let i=H.getRouteMethods(t);for(let n of i){let f=H.getRouteMetadata(t.prototype,n),r=H.getParameterMetadata(t.prototype,n),h=H.getDependencyMetadata(t.prototype,n);if(f&&f.method&&f.path!==void 0){let e=s?.prefix||"",c=this.normalizePath(e,f.path);this.metadata.registerRoute({target:t,propertyKey:n,method:f.method,path:c,middleware:[...s?.middleware||[],...f.middleware||[]],parameters:r||f.parameters||[],dependencies:h||f.dependencies||[],responses:f.responses||[],docs:f.docs})}}}get(t,s){this.registerFunctionalRoute("GET",t,s)}post(t,s){this.registerFunctionalRoute("POST",t,s)}put(t,s){this.registerFunctionalRoute("PUT",t,s)}delete(t,s){this.registerFunctionalRoute("DELETE",t,s)}patch(t,s){this.registerFunctionalRoute("PATCH",t,s)}route(t){return new Mt(this,t)}group(t,s){let i=this.groupPrefix;this.groupPrefix=this.normalizePath(this.groupPrefix,t),s(),this.groupPrefix=i}registerFunctionalRoute(t,s,i){let n=this.normalizePath(this.groupPrefix,s),f={target:vt,propertyKey:`${t.toLowerCase()}_${n}`,method:t,path:n,middleware:i.middleware||[],parameters:this.extractParametersFromSchema(i.schema),dependencies:[],responses:i.responses||[],docs:i.docs,handler:i.handler};this.metadata.registerRoute(f)}extractParametersFromSchema(t){let s=[],i=0;if(t?.body)s.push({index:i++,type:"body",schema:t.body,required:!0});if(t?.query)s.push({index:i++,type:"query",schema:t.query,required:!1});if(t?.params)s.push({index:i++,type:"param",schema:t.params,required:!0});if(t?.headers)s.push({index:i++,type:"header",schema:t.headers,required:!1});return s}use(t){this.globalMiddleware.push(t),this.hono.use("*",t)}useCors(t){let s=Jt(t);this.use(s)}useRateLimit(t){let s=kt(t);this.use(s)}useCompression(t){let s=qt(t);this.use(s)}usePlugin(t){this.pluginManager.register(t)}getPluginManager(){return this.pluginManager}onError(t){this.errorHandler.setCustomHandler(t)}getErrorHandler(){return this.errorHandler}normalizePath(...t){let s=t.filter((i)=>i!=="").join("/").replace(/\/+/g,"/").replace(/\/$/,"");return s.startsWith("/")?s:`/${s}`}getHono(){return this.hono}getMetadata(){return this.metadata}getContainer(){return this.container}getCompiler(){return this.compiler}getConfig(){return this.config}isCompiled(){return this.compiled}markCompiled(){this.compiled=!0}async compile(){if(this.compiled){console.warn("Routes have already been compiled. Skipping compilation.");return}await this.pluginManager.install(this),this.compiler.compile(),this.compiled=!0}async listen(t,s){if(!this.compiled)await this.compile();return this.createAdapter().listen(t,s)}createAdapter(){let t=this.config.adapter||"hono";switch(t){case"hono":{let{HonoAdapter:s}=bt(ot);return new s(this.hono)}case"express":{let{ExpressAdapter:s}=bt(It);return new s(this)}case"native":{let{HonoAdapter:s}=bt(ot);return new s(this.hono)}default:throw Error(`Unknown adapter type: ${t}. Supported adapters: 'hono', 'express', 'native'`)}}}class vt{}class Mt{app;path;constructor(t,s){this.app=t;this.path=s}get(t){return this.app.get(this.path,t),this}post(t){return this.app.post(this.path,t),this}put(t){return this.app.put(this.path,t),this}delete(t){return this.app.delete(this.path,t),this}patch(t){return this.app.patch(this.path,t),this}}function dt(t){let s={docs:!1,cors:!1,...t};return new St(s)}function Es(t,s,i,n){let f=t.getContainer(),r=typeof i==="function"?i:()=>i;f.register(s,{scope:n?.scope||"singleton",factory:r})}function mt(t){return new T(t)}async function xs(t,s){let i=dt(s);await t(i),await i.compile();let n=mt(i);return{app:i,client:n}}function Hs(t){t.getContainer().clear()}export{xs as setupTestApp,Es as mockDependency,mt as createTestClient,dt as createTestApp,Hs as clearMocks,T as TestClient};export{st as n,Bt as o,Gi as p,Qt as q,nt as r,ft as s,rt as t,et as u,ht as v,ct as w,ut as x,yt as y,gt as z,Xt as A,Vt as B,St as C,T as D,dt as E,Es as F,mt as G,xs as H,Hs as I};
2
+ import{J as H}from"../../chunk-2100y16g.js";import{K as kt,L as qt,M as vt}from"../../chunk-dtw2tbsd.js";import{N as Jt}from"../../chunk-vh4sxcpe.js";import"../../chunk-k66rn4fj.js";import{ja as Yt}from"../../chunk-mky5qqg0.js";import"../../chunk-yq3gf9ts.js";import{pa as Gt}from"../../chunk-9v7atckx.js";import"../../chunk-5q75d71c.js";import{ta as Cs,ua as bt,wa as Xt,xa as yt}from"../../chunk-y262e56g.js";var ot={};Xt(ot,{HonoAdapter:()=>Vt});class Vt{hono;name="hono";runtime;constructor(t){this.hono=t;this.runtime=Es()}listen(t,s){switch(this.runtime){case"bun":return this.listenBun(t,s);case"deno":return this.listenDeno(t,s);case"node":return this.listenNode(t,s);case"workerd":throw Error("Cloudflare Workers do not support listen(). Deploy using wrangler or export the handler with getHandler().");default:throw Error(`Unsupported runtime: ${this.runtime}. FastAPI-TS supports Bun, Node.js, Deno, and Cloudflare Workers.`)}}getHandler(){return this.hono.fetch}getRuntime(){return this.runtime}listenBun(t,s){let i=Bun.serve({port:t,fetch:this.hono.fetch});if(s)s();return i}listenDeno(t,s){let i=new AbortController;return Deno.serve({port:t,signal:i.signal,onListen:s},this.hono.fetch),{port:t,close:()=>i.abort()}}listenNode(t,s){try{let{serve:i}=(()=>{throw new Error("Cannot require module "+"@hono/node-server");})();return i({fetch:this.hono.fetch,port:t},s)}catch(i){throw Error("Node.js adapter requires @hono/node-server package. Install it with: npm install @hono/node-server")}}}var Es=()=>{if(typeof Bun<"u")return"bun";if(typeof Deno<"u")return"deno";if(typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers")return"workerd";if(typeof process<"u"&&process.versions&&process.versions.node)return"node";return"unknown"};var Zt={};Xt(Zt,{ExpressAdapter:()=>It});class It{app;name="express";express;constructor(t){this.app=t;try{let s=(()=>{throw new Error("Cannot require module "+"express");})();this.express=s(),this.setupBridge()}catch(s){throw Error("Express adapter requires express package. Install it with: npm install express")}}setupBridge(){let t=this.app.getHono();this.express.use(async(s,i)=>{try{let n=this.createWebRequest(s),f=await t.fetch(n);await this.sendExpressResponse(i,f)}catch(n){i.status(500).json({error:"Internal Server Error",message:n instanceof Error?n.message:"Unknown error"})}})}createWebRequest(t){let s=t.protocol||"http",i=t.get("host")||"localhost",n=`${s}://${i}${t.originalUrl||t.url}`,f=new Headers;for(let[h,e]of Object.entries(t.headers))if(typeof e==="string")f.set(h,e);else if(Array.isArray(e))e.forEach((c)=>f.append(h,c));let r={method:t.method,headers:f};if(t.method!=="GET"&&t.method!=="HEAD"){if(t.body)r.body=JSON.stringify(t.body),f.set("content-type","application/json")}return new Request(n,r)}async sendExpressResponse(t,s){if(t.status(s.status),s.headers.forEach((i,n)=>{t.setHeader(n,i)}),s.body){let i=s.headers.get("content-type")||"";if(i.includes("application/json")){let n=await s.json();t.json(n)}else if(i.includes("text/")){let n=await s.text();t.send(n)}else{let n=await s.arrayBuffer();t.send(Buffer.from(n))}}else t.end()}listen(t,s){return this.express.listen(t,s)}getHandler(){return this.express}getExpressApp(){return this.express}}class T{hono;constructor(t){this.hono=t.getHono()}async get(t,s){return this.request("GET",t,s)}async post(t,s){return this.request("POST",t,s)}async put(t,s){return this.request("PUT",t,s)}async delete(t,s){return this.request("DELETE",t,s)}async patch(t,s){return this.request("PATCH",t,s)}async request(t,s,i){let n=this.buildUrl(s,i?.query),f={method:t,headers:this.buildHeaders(i)};if(i?.body!==void 0)f.body=i.body;else if(i?.json!==void 0)f.body=JSON.stringify(i.json);let r=await this.hono.request(n,f),h=await r.text(),e;try{e=JSON.parse(h)}catch{e=h}return{status:r.status,headers:r.headers,body:e,text:h,json:async()=>JSON.parse(h),ok:r.ok}}buildUrl(t,s){if(!s||Object.keys(s).length===0)return t;let i=new URLSearchParams(s).toString();return`${t}?${i}`}buildHeaders(t){let s={...t?.headers};if(t?.json!==void 0&&!s["Content-Type"])s["Content-Type"]="application/json";return s}}var Z=(t,s,i)=>{return(n,f)=>{let r=-1;return h(0);async function h(e){if(e<=r)throw Error("next() called multiple times");r=e;let c,w=!1,y;if(t[e])y=t[e][0][0],n.req.routeIndex=e;else y=e===t.length&&f||void 0;if(y)try{c=await y(n,()=>h(e+1))}catch(u){if(u instanceof Error&&s)n.error=u,c=await s(u,n),w=!0;else throw u}else if(n.finalized===!1&&i)c=await i(n);if(c&&(n.finalized===!1||w))n.res=c;return n}}};var Ot=Symbol();var $t=async(t,s=Object.create(null))=>{let{all:i=!1,dot:n=!1}=s,r=(t instanceof z?t.raw.headers:t.headers).get("Content-Type");if(r?.startsWith("multipart/form-data")||r?.startsWith("application/x-www-form-urlencoded"))return ss(t,{all:i,dot:n});return{}};async function ss(t,s){let i=await t.formData();if(i)return is(i,s);return{}}function is(t,s){let i=Object.create(null);if(t.forEach((n,f)=>{if(!(s.all||f.endsWith("[]")))i[f]=n;else ns(i,f,n)}),s.dot)Object.entries(i).forEach(([n,f])=>{if(n.includes("."))fs(i,n,f),delete i[n]});return i}var ns=(t,s,i)=>{if(t[s]!==void 0)if(Array.isArray(t[s]))t[s].push(i);else t[s]=[t[s],i];else if(!s.endsWith("[]"))t[s]=i;else t[s]=[i]},fs=(t,s,i)=>{let n=t,f=s.split(".");f.forEach((r,h)=>{if(h===f.length-1)n[r]=i;else{if(!n[r]||typeof n[r]!=="object"||Array.isArray(n[r])||n[r]instanceof File)n[r]=Object.create(null);n=n[r]}})};var J=(t)=>{let s=t.split("/");if(s[0]==="")s.shift();return s},Ct=(t)=>{let{groups:s,path:i}=rs(t),n=J(i);return es(n,s)},rs=(t)=>{let s=[];return t=t.replace(/\{[^}]+\}/g,(i,n)=>{let f=`@${n}`;return s.push([f,i]),f}),{groups:s,path:t}},es=(t,s)=>{for(let i=s.length-1;i>=0;i--){let[n]=s[i];for(let f=t.length-1;f>=0;f--)if(t[f].includes(n)){t[f]=t[f].replace(n,s[i][1]);break}}return t},W={},Et=(t,s)=>{if(t==="*")return"*";let i=t.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(i){let n=`${t}#${s}`;if(!W[n])if(i[2])W[n]=s&&s[0]!==":"&&s[0]!=="*"?[n,i[1],new RegExp(`^${i[2]}(?=/${s})`)]:[t,i[1],new RegExp(`^${i[2]}$`)];else W[n]=[t,i[1],!0];return W[n]}return null},D=(t,s)=>{try{return s(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,(i)=>{try{return s(i)}catch{return i}})}},hs=(t)=>D(t,decodeURI),k=(t)=>{let s=t.url,i=s.indexOf("/",s.indexOf(":")+4),n=i;for(;n<s.length;n++){let f=s.charCodeAt(n);if(f===37){let r=s.indexOf("?",n),h=s.slice(i,r===-1?void 0:r);return hs(h.includes("%25")?h.replace(/%25/g,"%2525"):h)}else if(f===63)break}return s.slice(i,n)};var xt=(t)=>{let s=k(t);return s.length>1&&s.at(-1)==="/"?s.slice(0,-1):s},E=(t,s,...i)=>{if(i.length)s=E(s,...i);return`${t?.[0]==="/"?"":"/"}${t}${s==="/"?"":`${t?.at(-1)==="/"?"":"/"}${s?.[0]==="/"?s.slice(1):s}`}`},F=(t)=>{if(t.charCodeAt(t.length-1)!==63||!t.includes(":"))return null;let s=t.split("/"),i=[],n="";return s.forEach((f)=>{if(f!==""&&!/\:/.test(f))n+="/"+f;else if(/\:/.test(f))if(/\?/.test(f)){if(i.length===0&&n==="")i.push("/");else i.push(n);let r=f.replace("?","");n+="/"+r,i.push(n)}else n+="/"+f}),i.filter((f,r,h)=>h.indexOf(f)===r)},Y=(t)=>{if(!/[%+]/.test(t))return t;if(t.indexOf("+")!==-1)t=t.replace(/\+/g," ");return t.indexOf("%")!==-1?D(t,K):t},Ht=(t,s,i)=>{let n;if(!i&&s&&!/[%+]/.test(s)){let h=t.indexOf(`?${s}`,8);if(h===-1)h=t.indexOf(`&${s}`,8);while(h!==-1){let e=t.charCodeAt(h+s.length+1);if(e===61){let c=h+s.length+2,w=t.indexOf("&",c);return Y(t.slice(c,w===-1?void 0:w))}else if(e==38||isNaN(e))return"";h=t.indexOf(`&${s}`,h+1)}if(n=/[%+]/.test(t),!n)return}let f={};n??=/[%+]/.test(t);let r=t.indexOf("?",8);while(r!==-1){let h=t.indexOf("&",r+1),e=t.indexOf("=",r);if(e>h&&h!==-1)e=-1;let c=t.slice(r+1,e===-1?h===-1?void 0:h:e);if(n)c=Y(c);if(r=h,c==="")continue;let w;if(e===-1)w="";else if(w=t.slice(e+1,h===-1?void 0:h),n)w=Y(w);if(i){if(!(f[c]&&Array.isArray(f[c])))f[c]=[];f[c].push(w)}else f[c]??=w}return s?f[s]:f},jt=Ht,Dt=(t,s)=>{return Ht(t,s,!0)},K=decodeURIComponent;var lt=(t)=>D(t,K),z=class{raw;#s;#t;routeIndex=0;path;bodyCache={};constructor(t,s="/",i=[[]]){this.raw=t,this.path=s,this.#t=i,this.#s={}}param(t){return t?this.#i(t):this.#r()}#i(t){let s=this.#t[0][this.routeIndex][1][t],i=this.#f(s);return i&&/\%/.test(i)?lt(i):i}#r(){let t={},s=Object.keys(this.#t[0][this.routeIndex][1]);for(let i of s){let n=this.#f(this.#t[0][this.routeIndex][1][i]);if(n!==void 0)t[i]=/\%/.test(n)?lt(n):n}return t}#f(t){return this.#t[1]?this.#t[1][t]:t}query(t){return jt(this.url,t)}queries(t){return Dt(this.url,t)}header(t){if(t)return this.raw.headers.get(t)??void 0;let s={};return this.raw.headers.forEach((i,n)=>{s[n]=i}),s}async parseBody(t){return this.bodyCache.parsedBody??=await $t(this,t)}#n=(t)=>{let{bodyCache:s,raw:i}=this,n=s[t];if(n)return n;let f=Object.keys(s)[0];if(f)return s[f].then((r)=>{if(f==="json")r=JSON.stringify(r);return new Response(r)[t]()});return s[t]=i[t]()};json(){return this.#n("text").then((t)=>JSON.parse(t))}text(){return this.#n("text")}arrayBuffer(){return this.#n("arrayBuffer")}blob(){return this.#n("blob")}formData(){return this.#n("formData")}addValidatedData(t,s){this.#s[t]=s}valid(t){return this.#s[t]}get url(){return this.raw.url}get method(){return this.raw.method}get[Ot](){return this.#t}get matchedRoutes(){return this.#t[0].map(([[,t]])=>t)}get routePath(){return this.#t[0].map(([[,t]])=>t)[this.routeIndex].path}};var Nt={Stringify:1,BeforeStream:2,Stream:3},cs=(t,s)=>{let i=new String(t);return i.isEscaped=!0,i.callbacks=s,i};var q=async(t,s,i,n,f)=>{if(typeof t==="object"&&!(t instanceof String)){if(!(t instanceof Promise))t=t.toString();if(t instanceof Promise)t=await t}let r=t.callbacks;if(!r?.length)return Promise.resolve(t);if(f)f[0]+=t;else f=[t];let h=Promise.all(r.map((e)=>e({phase:s,buffer:f,context:n}))).then((e)=>Promise.all(e.filter(Boolean).map((c)=>q(c,s,!1,n,f))).then(()=>f[0]));if(i)return cs(await h,r);else return h};var ws="text/plain; charset=UTF-8",v=(t,s)=>{return{"Content-Type":t,...s}},Ut=class{#s;#t;env={};#i;finalized=!1;error;#r;#f;#n;#y;#c;#w;#h;#u;#g;constructor(t,s){if(this.#s=t,s)this.#f=s.executionCtx,this.env=s.env,this.#w=s.notFoundHandler,this.#g=s.path,this.#u=s.matchResult}get req(){return this.#t??=new z(this.#s,this.#g,this.#u),this.#t}get event(){if(this.#f&&"respondWith"in this.#f)return this.#f;else throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#f)return this.#f;else throw Error("This context has no ExecutionContext")}get res(){return this.#n||=new Response(null,{headers:this.#h??=new Headers})}set res(t){if(this.#n&&t){t=new Response(t.body,t);for(let[s,i]of this.#n.headers.entries()){if(s==="content-type")continue;if(s==="set-cookie"){let n=this.#n.headers.getSetCookie();t.headers.delete("set-cookie");for(let f of n)t.headers.append("set-cookie",f)}else t.headers.set(s,i)}}this.#n=t,this.finalized=!0}render=(...t)=>{return this.#c??=(s)=>this.html(s),this.#c(...t)};setLayout=(t)=>this.#y=t;getLayout=()=>this.#y;setRenderer=(t)=>{this.#c=t};header=(t,s,i)=>{if(this.finalized)this.#n=new Response(this.#n.body,this.#n);let n=this.#n?this.#n.headers:this.#h??=new Headers;if(s===void 0)n.delete(t);else if(i?.append)n.append(t,s);else n.set(t,s)};status=(t)=>{this.#r=t};set=(t,s)=>{this.#i??=new Map,this.#i.set(t,s)};get=(t)=>{return this.#i?this.#i.get(t):void 0};get var(){if(!this.#i)return{};return Object.fromEntries(this.#i)}#e(t,s,i){let n=this.#n?new Headers(this.#n.headers):this.#h??new Headers;if(typeof s==="object"&&"headers"in s){let r=s.headers instanceof Headers?s.headers:new Headers(s.headers);for(let[h,e]of r)if(h.toLowerCase()==="set-cookie")n.append(h,e);else n.set(h,e)}if(i)for(let[r,h]of Object.entries(i))if(typeof h==="string")n.set(r,h);else{n.delete(r);for(let e of h)n.append(r,e)}let f=typeof s==="number"?s:s?.status??this.#r;return new Response(t,{status:f,headers:n})}newResponse=(...t)=>this.#e(...t);body=(t,s,i)=>this.#e(t,s,i);text=(t,s,i)=>{return!this.#h&&!this.#r&&!s&&!i&&!this.finalized?new Response(t):this.#e(t,s,v(ws,i))};json=(t,s,i)=>{return this.#e(JSON.stringify(t),s,v("application/json",i))};html=(t,s,i)=>{let n=(f)=>this.#e(f,s,v("text/html; charset=UTF-8",i));return typeof t==="object"?q(t,Nt.Stringify,!1,{}).then(n):n(t)};redirect=(t,s)=>{let i=String(t);return this.header("Location",!/[^\x00-\xFF]/.test(i)?i:encodeURI(i)),this.newResponse(null,s??302)};notFound=()=>{return this.#w??=()=>new Response,this.#w(this)}};var g="ALL",Kt="all",At=["get","post","put","delete","options","patch"],Q="Can not add a route since the matcher is already built.",B=class extends Error{};var Lt="__COMPOSED_HANDLER";var ys=(t)=>{return t.text("404 Not Found",404)},Rt=(t,s)=>{if("getResponse"in t){let i=t.getResponse();return s.newResponse(i.body,i)}return console.error(t),s.text("Internal Server Error",500)},M=class{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#s="/";routes=[];constructor(t={}){[...At,Kt].forEach((f)=>{this[f]=(r,...h)=>{if(typeof r==="string")this.#s=r;else this.#r(f,this.#s,r);return h.forEach((e)=>{this.#r(f,this.#s,e)}),this}}),this.on=(f,r,...h)=>{for(let e of[r].flat()){this.#s=e;for(let c of[f].flat())h.map((w)=>{this.#r(c.toUpperCase(),this.#s,w)})}return this},this.use=(f,...r)=>{if(typeof f==="string")this.#s=f;else this.#s="*",r.unshift(f);return r.forEach((h)=>{this.#r(g,this.#s,h)}),this};let{strict:i,...n}=t;Object.assign(this,n),this.getPath=i??!0?t.getPath??k:xt}#t(){let t=new M({router:this.router,getPath:this.getPath});return t.errorHandler=this.errorHandler,t.#i=this.#i,t.routes=this.routes,t}#i=ys;errorHandler=Rt;route(t,s){let i=this.basePath(t);return s.routes.map((n)=>{let f;if(s.errorHandler===Rt)f=n.handler;else f=async(r,h)=>(await Z([],s.errorHandler)(r,()=>n.handler(r,h))).res,f[Lt]=n.handler;i.#r(n.method,n.path,f)}),this}basePath(t){let s=this.#t();return s._basePath=E(this._basePath,t),s}onError=(t)=>{return this.errorHandler=t,this};notFound=(t)=>{return this.#i=t,this};mount(t,s,i){let n,f;if(i)if(typeof i==="function")f=i;else if(f=i.optionHandler,i.replaceRequest===!1)n=(e)=>e;else n=i.replaceRequest;let r=f?(e)=>{let c=f(e);return Array.isArray(c)?c:[c]}:(e)=>{let c=void 0;try{c=e.executionCtx}catch{}return[e.env,c]};n||=(()=>{let e=E(this._basePath,t),c=e==="/"?0:e.length;return(w)=>{let y=new URL(w.url);return y.pathname=y.pathname.slice(c)||"/",new Request(y,w)}})();let h=async(e,c)=>{let w=await s(n(e.req.raw),...r(e));if(w)return w;await c()};return this.#r(g,E(t,"*"),h),this}#r(t,s,i){t=t.toUpperCase(),s=E(this._basePath,s);let n={basePath:this._basePath,path:s,method:t,handler:i};this.router.add(t,s,[i,n]),this.routes.push(n)}#f(t,s){if(t instanceof Error)return this.errorHandler(t,s);throw t}#n(t,s,i,n){if(n==="HEAD")return(async()=>new Response(null,await this.#n(t,s,i,"GET")))();let f=this.getPath(t,{env:i}),r=this.router.match(n,f),h=new Ut(t,{path:f,matchResult:r,env:i,executionCtx:s,notFoundHandler:this.#i});if(r[0].length===1){let c;try{c=r[0][0][0][0](h,async()=>{h.res=await this.#i(h)})}catch(w){return this.#f(w,h)}return c instanceof Promise?c.then((w)=>w||(h.finalized?h.res:this.#i(h))).catch((w)=>this.#f(w,h)):c??this.#i(h)}let e=Z(r[0],this.errorHandler,this.#i);return(async()=>{try{let c=await e(h);if(!c.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return c.res}catch(c){return this.#f(c,h)}})()}fetch=(t,...s)=>{return this.#n(t,s[1],s[0],t.method)};request=(t,s,i,n)=>{if(t instanceof Request)return this.fetch(s?new Request(t,s):t,i,n);return t=t.toString(),this.fetch(new Request(/^https?:\/\//.test(t)?t:`http://localhost${E("/",t)}`,s),i,n)};fire=()=>{addEventListener("fetch",(t)=>{t.respondWith(this.#n(t.request,t,void 0,t.request.method))})}};var G="[^/]+",A=".*",L="(?:|/.*)",x=Symbol(),us=new Set(".\\+*[^]$()");function gs(t,s){if(t.length===1)return s.length===1?t<s?-1:1:-1;if(s.length===1)return 1;if(t===A||t===L)return 1;else if(s===A||s===L)return-1;if(t===G)return 1;else if(s===G)return-1;return t.length===s.length?t<s?-1:1:s.length-t.length}var X=class{#s;#t;#i=Object.create(null);insert(t,s,i,n,f){if(t.length===0){if(this.#s!==void 0)throw x;if(f)return;this.#s=s;return}let[r,...h]=t,e=r==="*"?h.length===0?["","",A]:["","",G]:r==="/*"?["","",L]:r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(e){let w=e[1],y=e[2]||G;if(w&&e[2]){if(y===".*")throw x;if(y=y.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(y))throw x}if(c=this.#i[y],!c){if(Object.keys(this.#i).some((u)=>u!==A&&u!==L))throw x;if(f)return;if(c=this.#i[y]=new X,w!=="")c.#t=n.varIndex++}if(!f&&w!=="")i.push([w,c.#t])}else if(c=this.#i[r],!c){if(Object.keys(this.#i).some((w)=>w.length>1&&w!==A&&w!==L))throw x;if(f)return;c=this.#i[r]=new X}c.insert(h,s,i,n,f)}buildRegExpStr(){let s=Object.keys(this.#i).sort(gs).map((i)=>{let n=this.#i[i];return(typeof n.#t==="number"?`(${i})@${n.#t}`:us.has(i)?`\\${i}`:i)+n.buildRegExpStr()});if(typeof this.#s==="number")s.unshift(`#${this.#s}`);if(s.length===0)return"";if(s.length===1)return s[0];return"(?:"+s.join("|")+")"}};var Tt=class{#s={varIndex:0};#t=new X;insert(t,s,i){let n=[],f=[];for(let h=0;;){let e=!1;if(t=t.replace(/\{[^}]+\}/g,(c)=>{let w=`@\\${h}`;return f[h]=[w,c],h++,e=!0,w}),!e)break}let r=t.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let h=f.length-1;h>=0;h--){let[e]=f[h];for(let c=r.length-1;c>=0;c--)if(r[c].indexOf(e)!==-1){r[c]=r[c].replace(e,f[h][1]);break}}return this.#t.insert(r,s,n,this.#s,i),n}buildRegExp(){let t=this.#t.buildRegExpStr();if(t==="")return[/^$/,[],[]];let s=0,i=[],n=[];return t=t.replace(/#(\d+)|@(\d+)|\.\*\$/g,(f,r,h)=>{if(r!==void 0)return i[++s]=Number(r),"$()";if(h!==void 0)return n[Number(h)]=++s,"";return""}),[new RegExp(`^${t}`),i,n]}};var zt=[],Ps=[/^$/,[],Object.create(null)],Wt=Object.create(null);function Ft(t){return Wt[t]??=new RegExp(t==="*"?"":`^${t.replace(/\/\*$|([.\\+*[^\]$()])/g,(s,i)=>i?`\\${i}`:"(?:|/.*)")}$`)}function os(){Wt=Object.create(null)}function bs(t){let s=new Tt,i=[];if(t.length===0)return Ps;let n=t.map((w)=>[!/\*|\/:/.test(w[0]),...w]).sort(([w,y],[u,o])=>w?1:u?-1:y.length-o.length),f=Object.create(null);for(let w=0,y=-1,u=n.length;w<u;w++){let[o,S,P]=n[w];if(o)f[S]=[P.map(([_])=>[_,Object.create(null)]),zt];else y++;let b;try{b=s.insert(S,y,o)}catch(_){throw _===x?new B(S):_}if(o)continue;i[y]=P.map(([_,j])=>{let N=Object.create(null);j-=1;for(;j>=0;j--){let[O,I]=b[j];N[O]=I}return[_,N]})}let[r,h,e]=s.buildRegExp();for(let w=0,y=i.length;w<y;w++)for(let u=0,o=i[w].length;u<o;u++){let S=i[w][u]?.[1];if(!S)continue;let P=Object.keys(S);for(let b=0,_=P.length;b<_;b++)S[P[b]]=e[S[P[b]]]}let c=[];for(let w in h)c[w]=i[h[w]];return[r,c,f]}function l(t,s){if(!t)return;for(let i of Object.keys(t).sort((n,f)=>f.length-n.length))if(Ft(i).test(s))return[...t[i]];return}var d=class{name="RegExpRouter";#s;#t;constructor(){this.#s={[g]:Object.create(null)},this.#t={[g]:Object.create(null)}}add(t,s,i){let n=this.#s,f=this.#t;if(!n||!f)throw Error(Q);if(!n[t])[n,f].forEach((e)=>{e[t]=Object.create(null),Object.keys(e[g]).forEach((c)=>{e[t][c]=[...e[g][c]]})});if(s==="/*")s="*";let r=(s.match(/\/:/g)||[]).length;if(/\*$/.test(s)){let e=Ft(s);if(t===g)Object.keys(n).forEach((c)=>{n[c][s]||=l(n[c],s)||l(n[g],s)||[]});else n[t][s]||=l(n[t],s)||l(n[g],s)||[];Object.keys(n).forEach((c)=>{if(t===g||t===c)Object.keys(n[c]).forEach((w)=>{e.test(w)&&n[c][w].push([i,r])})}),Object.keys(f).forEach((c)=>{if(t===g||t===c)Object.keys(f[c]).forEach((w)=>e.test(w)&&f[c][w].push([i,r]))});return}let h=F(s)||[s];for(let e=0,c=h.length;e<c;e++){let w=h[e];Object.keys(f).forEach((y)=>{if(t===g||t===y)f[y][w]||=[...l(n[y],w)||l(n[g],w)||[]],f[y][w].push([i,r-c+e+1])})}}match(t,s){os();let i=this.#i();return this.match=(n,f)=>{let r=i[n]||i[g],h=r[2][f];if(h)return h;let e=f.match(r[0]);if(!e)return[[],zt];let c=e.indexOf("",1);return[r[1][c],e]},this.match(t,s)}#i(){let t=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#s)).forEach((s)=>{t[s]||=this.#r(s)}),this.#s=this.#t=void 0,t}#r(t){let s=[],i=t===g;if([this.#s,this.#t].forEach((n)=>{let f=n[t]?Object.keys(n[t]).map((r)=>[r,n[t][r]]):[];if(f.length!==0)i||=!0,s.push(...f);else if(t!==g)s.push(...Object.keys(n[g]).map((r)=>[r,n[g][r]]))}),!i)return null;else return bs(s)}};var m=class{name="SmartRouter";#s=[];#t=[];constructor(t){this.#s=t.routers}add(t,s,i){if(!this.#t)throw Error(Q);this.#t.push([t,s,i])}match(t,s){if(!this.#t)throw Error("Fatal error");let i=this.#s,n=this.#t,f=i.length,r=0,h;for(;r<f;r++){let e=i[r];try{for(let c=0,w=n.length;c<w;c++)e.add(...n[c]);h=e.match(t,s)}catch(c){if(c instanceof B)continue;throw c}this.match=e.match.bind(e),this.#s=[e],this.#t=void 0;break}if(r===f)throw Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,h}get activeRouter(){if(this.#t||this.#s.length!==1)throw Error("No active router has been determined yet.");return this.#s[0]}};var R=Object.create(null),a=class{#s;#t;#i;#r=0;#f=R;constructor(t,s,i){if(this.#t=i||Object.create(null),this.#s=[],t&&s){let n=Object.create(null);n[t]={handler:s,possibleKeys:[],score:0},this.#s=[n]}this.#i=[]}insert(t,s,i){this.#r=++this.#r;let n=this,f=Ct(s),r=[];for(let h=0,e=f.length;h<e;h++){let c=f[h],w=f[h+1],y=Et(c,w),u=Array.isArray(y)?y[0]:c;if(u in n.#t){if(n=n.#t[u],y)r.push(y[1]);continue}if(n.#t[u]=new a,y)n.#i.push(y),r.push(y[1]);n=n.#t[u]}return n.#s.push({[t]:{handler:i,possibleKeys:r.filter((h,e,c)=>c.indexOf(h)===e),score:this.#r}}),n}#n(t,s,i,n){let f=[];for(let r=0,h=t.#s.length;r<h;r++){let e=t.#s[r],c=e[s]||e[g],w={};if(c!==void 0){if(c.params=Object.create(null),f.push(c),i!==R||n&&n!==R)for(let y=0,u=c.possibleKeys.length;y<u;y++){let o=c.possibleKeys[y],S=w[c.score];c.params[o]=n?.[o]&&!S?n[o]:i[o]??n?.[o],w[c.score]=!0}}}return f}search(t,s){let i=[];this.#f=R;let f=[this],r=J(s),h=[];for(let e=0,c=r.length;e<c;e++){let w=r[e],y=e===c-1,u=[];for(let o=0,S=f.length;o<S;o++){let P=f[o],b=P.#t[w];if(b)if(b.#f=P.#f,y){if(b.#t["*"])i.push(...this.#n(b.#t["*"],t,P.#f));i.push(...this.#n(b,t,P.#f))}else u.push(b);for(let _=0,j=P.#i.length;_<j;_++){let N=P.#i[_],O=P.#f===R?{}:{...P.#f};if(N==="*"){let C=P.#t["*"];if(C)i.push(...this.#n(C,t,P.#f)),C.#f=O,u.push(C);continue}let[I,_t,U]=N;if(!w&&!(U instanceof RegExp))continue;let $=P.#t[I],pt=r.slice(e).join("/");if(U instanceof RegExp){let C=U.exec(pt);if(C){if(O[_t]=C[0],i.push(...this.#n($,t,P.#f,O)),Object.keys($.#t).length){$.#f=O;let ts=C[0].match(/\//)?.length??0;(h[ts]||=[]).push($)}continue}}if(U===!0||U.test(w))if(O[_t]=w,y){if(i.push(...this.#n($,t,O,P.#f)),$.#t["*"])i.push(...this.#n($.#t["*"],t,O,P.#f))}else $.#f=O,u.push($)}}f=u.concat(h.shift()??[])}if(i.length>1)i.sort((e,c)=>{return e.score-c.score});return[i.map(({handler:e,params:c})=>[e,c])]}};var p=class{name="TrieRouter";#s;constructor(){this.#s=new a}add(t,s,i){let n=F(s);if(n){for(let f=0,r=n.length;f<r;f++)this.#s.insert(t,n[f],i);return}this.#s.insert(t,s,i)}match(t,s){return this.#s.search(t,s)}};var tt=class extends M{constructor(t={}){super(t);this.router=t.router??new m({routers:[new d,new p]})}};class st{singletons=new Map;requestScoped=new WeakMap;providers=new Map;resolutionStack=new Set;providerNameCache=new WeakMap;stats={singletonHits:0,singletonMisses:0,requestHits:0,requestMisses:0,transientCreations:0};register(t,s){this.providers.set(t,s||{scope:"transient"})}async resolve(t,s){let i=this.providers.get(t)||{scope:s?.scope||"transient"},n=s?.scope||i.scope||"transient";if(n==="singleton"){if(this.singletons.has(t))return this.stats.singletonHits++,this.singletons.get(t);if(this.stats.singletonMisses++,this.resolutionStack.has(t))throw Error(`Circular dependency detected: ${this.buildCircularDependencyMessage(t)}`);this.resolutionStack.add(t);try{let f=await this.create(t,i,s?.context);return this.singletons.set(t,f),f}finally{this.resolutionStack.delete(t)}}if(n==="request"&&s?.context){let f=this.requestScoped.get(s.context);if(f?.has(t))return this.stats.requestHits++,f.get(t);if(this.stats.requestMisses++,!f)f=new Map,this.requestScoped.set(s.context,f);if(this.resolutionStack.has(t))throw Error(`Circular dependency detected: ${this.buildCircularDependencyMessage(t)}`);this.resolutionStack.add(t);try{let r=await this.create(t,i,s.context);return f.set(t,r),r}finally{this.resolutionStack.delete(t)}}if(this.stats.transientCreations++,this.resolutionStack.has(t))throw Error(`Circular dependency detected: ${this.buildCircularDependencyMessage(t)}`);this.resolutionStack.add(t);try{return await this.create(t,i,s?.context)}finally{this.resolutionStack.delete(t)}}buildCircularDependencyMessage(t){let s=Array.from(this.resolutionStack),i=this.getProviderName(t);return s.map((f)=>this.getProviderName(f)).join(" -> ")+" -> "+i}async create(t,s,i){if(s.factory)return s.factory();if(typeof t==="function")if(t.prototype&&t.prototype.constructor===t){let n=new t;return await this.resolveNestedDependencies(n,i),n}else{let n=t();return n instanceof Promise?await n:n}throw Error("Invalid provider type")}async resolveNestedDependencies(t,s){}getProviderName(t){let s=this.providerNameCache.get(t);if(s)return s;let i;if(typeof t==="function")if(t.name)i=t.name;else i=t.toString().substring(0,50);else i=String(t);return this.providerNameCache.set(t,i),i}clear(){this.singletons.clear(),this.providers.clear(),this.resolutionStack.clear(),this.providerNameCache=new WeakMap,this.resetStats()}clearRequestScope(t){this.requestScoped.delete(t)}getStats(){let t=this.stats.singletonHits+this.stats.singletonMisses,s=t>0?this.stats.singletonHits/t*100:0,i=this.stats.requestHits+this.stats.requestMisses,n=i>0?this.stats.requestHits/i*100:0;return{singletonHits:this.stats.singletonHits,singletonMisses:this.stats.singletonMisses,singletonHitRate:Math.round(s*100)/100,requestHits:this.stats.requestHits,requestMisses:this.stats.requestMisses,requestHitRate:Math.round(n*100)/100,transientCreations:this.stats.transientCreations}}resetStats(){this.stats={singletonHits:0,singletonMisses:0,requestHits:0,requestMisses:0,transientCreations:0}}}var Ss=/^[\w!#$%&'*.^`|~+-]+$/,_s=/^[ !#-:<-[\]-~]*$/,it=(t,s)=>{if(s&&t.indexOf(s)===-1)return{};let i=t.trim().split(";"),n={};for(let f of i){f=f.trim();let r=f.indexOf("=");if(r===-1)continue;let h=f.substring(0,r).trim();if(s&&s!==h||!Ss.test(h))continue;let e=f.substring(r+1).trim();if(e.startsWith('"')&&e.endsWith('"'))e=e.slice(1,-1);if(_s.test(e)){if(n[h]=e.indexOf("%")!==-1?D(e,K):e,s)break}}return n};var Os=(t,s,i={})=>{let n=`${t}=${s}`;if(t.startsWith("__Secure-")&&!i.secure)throw Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!i.secure)throw Error("__Host- Cookie must have Secure attributes");if(i.path!=="/")throw Error('__Host- Cookie must have Path attributes with "/"');if(i.domain)throw Error("__Host- Cookie must not have Domain attributes")}if(i&&typeof i.maxAge==="number"&&i.maxAge>=0){if(i.maxAge>34560000)throw Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");n+=`; Max-Age=${i.maxAge|0}`}if(i.domain&&i.prefix!=="host")n+=`; Domain=${i.domain}`;if(i.path)n+=`; Path=${i.path}`;if(i.expires){if(i.expires.getTime()-Date.now()>34560000000)throw Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");n+=`; Expires=${i.expires.toUTCString()}`}if(i.httpOnly)n+="; HttpOnly";if(i.secure)n+="; Secure";if(i.sameSite)n+=`; SameSite=${i.sameSite.charAt(0).toUpperCase()+i.sameSite.slice(1)}`;if(i.priority)n+=`; Priority=${i.priority.charAt(0).toUpperCase()+i.priority.slice(1)}`;if(i.partitioned){if(!i.secure)throw Error("Partitioned Cookie must have Secure attributes");n+="; Partitioned"}return n},V=(t,s,i)=>{return s=encodeURIComponent(s),Os(t,s,i)};var Qt=(t,s,i)=>{let n=t.req.raw.headers.get("Cookie");if(typeof s==="string"){if(!n)return;let r=s;if(i==="secure")r="__Secure-"+s;else if(i==="host")r="__Host-"+s;return it(n,r)[r]}if(!n)return{};return it(n)};var $s=(t,s,i)=>{let n;if(i?.prefix==="secure")n=V("__Secure-"+t,s,{path:"/",...i,secure:!0});else if(i?.prefix==="host")n=V("__Host-"+t,s,{...i,path:"/",secure:!0,domain:void 0});else n=V(t,s,{path:"/",...i});return n},Xi=(t,s,i,n)=>{let f=$s(s,i,n);t.header("Set-Cookie",f,{append:!0})};class Bt{static json(t,s=200,i){return new nt(t,s,i)}static html(t,s=200){return new ft(t,s)}static file(t,s){return new et(t,s)}static stream(t,s){return new ht(t,s)}static redirect(t,s=302){return new rt(t,s)}}class nt{data;status;headers;constructor(t,s=200,i={}){this.data=t;this.status=s;this.headers=i}toHonoResponse(t){return t.json(this.data,this.status,this.headers)}}class ft{content;status;constructor(t,s=200){this.content=t;this.status=s}toHonoResponse(t){return t.html(this.content,this.status)}}class rt{url;status;constructor(t,s=302){this.url=t;this.status=s}toHonoResponse(t){return t.redirect(this.url,this.status)}}class et{path;options;constructor(t,s){this.path=t;this.options=s}async toHonoResponse(t){try{let s=typeof Bun<"u"?Bun.file(this.path):await this.readFileNode(this.path),n={"Content-Type":this.options?.contentType||this.guessContentType(this.path)};if(this.options?.download||this.options?.filename){let f=this.options?.filename||this.path.split("/").pop()||"download",r=this.options?.download?"attachment":"inline";n["Content-Disposition"]=`${r}; filename="${f}"`}if(typeof Bun<"u"&&s instanceof Blob)return t.body(s,200,n);else return t.body(s,200,n)}catch(s){return t.json({error:"File not found",message:s instanceof Error?s.message:"Unknown error"},404)}}async readFileNode(t){throw Error("File reading in Node.js requires fs module - use Bun runtime or implement adapter")}guessContentType(t){let s=t.split(".").pop()?.toLowerCase();return{html:"text/html",css:"text/css",js:"application/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",svg:"image/svg+xml",pdf:"application/pdf",txt:"text/plain",xml:"application/xml"}[s||""]||"application/octet-stream"}}class ht{stream;options;constructor(t,s){this.stream=t;this.options=s}toHonoResponse(t){let s={"Content-Type":this.options?.contentType||"application/octet-stream",...this.options?.headers};return t.body(this.stream,200,s)}}class ct{static serialize(t,s){if(s===null||s===void 0)return t.body(null,204);if(s instanceof Bt)return s;if(s instanceof nt)return s.toHonoResponse(t);if(s instanceof ft)return s.toHonoResponse(t);if(s instanceof et)return s.toHonoResponse(t);if(s instanceof ht)return s.toHonoResponse(t);if(s instanceof rt)return s.toHonoResponse(t);if(s&&typeof s.toHonoResponse==="function")return s.toHonoResponse(t);return t.json(s)}}class wt{static compile(t){let s=this.compilePathRegex(t.path),i=this.resolveParameterOrder(t.parameters),n=this.resolveDependencyOrder(t.dependencies),f=this.calculateMaxArgumentIndex(t.parameters,t.dependencies),r=this.computeParameterFlags(t.parameters);return{...t,pathRegex:s,parameterOrder:i,dependencyOrder:n,maxArgumentIndex:f,...r}}static compilePathRegex(t){let s=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return s=s.replace(/\\\{([^}]+)\\\}/g,"(?<$1>[^/]+)"),s=s.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"(?<$1>[^/]+)"),s=`^${s}$`,new RegExp(s)}static resolveParameterOrder(t){if(!t||t.length===0)return[];return t.map((s)=>s.index).filter((s)=>s!==void 0).sort((s,i)=>s-i)}static resolveDependencyOrder(t){if(!t||t.length===0)return[];return t.map((s)=>s.index).filter((s)=>s!==void 0).sort((s,i)=>s-i)}static calculateMaxArgumentIndex(t,s){let i=-1;if(t&&t.length>0){let n=Math.max(...t.map((f)=>f.index));i=Math.max(i,n)}if(s&&s.length>0){let n=Math.max(...s.map((f)=>f.index));i=Math.max(i,n)}return i}static computeParameterFlags(t){if(!t||t.length===0)return{hasBody:!1,hasQuery:!1,hasParams:!1,hasHeaders:!1,hasCookies:!1,hasDependencies:!1};return{hasBody:t.some((s)=>s.type==="body"),hasQuery:t.some((s)=>s.type==="query"),hasParams:t.some((s)=>s.type==="param"),hasHeaders:t.some((s)=>s.type==="header"),hasCookies:t.some((s)=>s.type==="cookie"),hasDependencies:!1}}static compileAll(t){return t.map((s)=>this.compile(s))}}class ut{app;metadata;container;validator;errorHandler;compiledRoutes=new Map;constructor(t,s,i,n,f){this.app=t;this.metadata=s;this.container=i;this.validator=n;this.errorHandler=f}compile(){let t=this.metadata.getRoutes(),s=wt.compileAll(t);for(let i of s){let n=`${i.target.name}:${i.propertyKey}`;this.compiledRoutes.set(n,i);let f=this.createHandler(i),r=this.normalizePath(i.path),h=i.method.toLowerCase();if(i.middleware&&i.middleware.length>0)this.app[h](r,...i.middleware,f);else this.app[h](r,f)}}normalizePath(t){if(!t.startsWith("/"))t="/"+t;if(t=t.replace(/\{([^}]+)\}/g,":$1"),t.length>1&&t.endsWith("/"))t=t.slice(0,-1);return t}createHandler(t){return async(s)=>{try{s.set("routeMetadata",t);let i=await this.extractParameters(s,t.parameters),n=await this.resolveDependencies(s,t.dependencies),f=this.mergeArguments(i,n,t.parameters,t.maxArgumentIndex),r;if(t.handler)r=await t.handler(s,...f);else{let h=await this.container.resolve(t.target,{scope:"transient",context:s});if(typeof h[t.propertyKey]!=="function")throw Error(`Method ${t.propertyKey} not found on controller ${t.target.name}`);r=await h[t.propertyKey](...f)}return this.serializeResponse(s,r)}catch(i){return await this.handleError(s,i)}}}serializeResponse(t,s){return ct.serialize(t,s)}getRouteMetadataForContext(t){return t.get("routeMetadata")||null}isAuthRequired(t){if(t.auth?.required)return!0;return t.parameters.some((s)=>s.type==="current-user")}async handleError(t,s){return await this.errorHandler.handle(s,t)}async extractParameters(t,s){let i=[];for(let n of s){if(!n)continue;let f;switch(n.type){case"body":try{f=await t.req.json()}catch(e){f=null}break;case"query":if(n.name)f=t.req.query(n.name);else f=t.req.query();if(n.schema&&f!==void 0)try{f=n.schema.parse(f)}catch(e){throw new Gt(`Invalid query parameter: ${e}`)}break;case"param":if(n.name)f=t.req.param(n.name);else f=t.req.param();break;case"header":if(n.name)f=t.req.header(n.name);else{let e={};t.req.raw.headers.forEach((c,w)=>{e[w]=c}),f=e}break;case"cookie":if(n.name)f=Qt(t,n.name);else{let e=t.req.header("cookie");if(e)f=Object.fromEntries(e.split(";").map((c)=>{let[w,...y]=c.trim().split("=");return[w,y.join("=")]}));else f={}}break;case"request":f=t.req;break;case"response":case"context":f=t;break;case"current-user":f=t.get("auth.user")||null;let r=this.getRouteMetadataForContext(t);if(r&&this.isAuthRequired(r)){if(!f){let e=t.get("auth.error")||"Authentication required",{AuthenticationException:c}=await import("../../chunk-s5z0wb7e.js");throw new c(e)}}break;case"token":f=t.get("auth.token")||null;break;case"oauth-user":f=t.get("oauth.user")||null;break;case"oauth-token":f=t.get("oauth.token")||null;break;case"current-session":f=t.get("session")||null;break;case"session-data":let h=t.get("session");if(h&&n.metadata?.key)f=h.data[n.metadata.key];else if(h)f=h.data;else f=null;break;case"csrf-token":f=t.get("csrf.token")||null;break;case"filtered-resource":f=t.get("filtered.resource")||null;break;case"filtered-attributes":f=t.get("filtered.attributes")||[];break;default:f=void 0}if(n.schema)try{f=await this.validator.validate(f,n.schema)}catch(r){throw r}i[n.index]=f}return i}mergeArguments(t,s,i,n){let r=i.filter((w)=>w!==void 0&&w.index!==void 0).map((w)=>w.index),h=r.length>0?Math.max(...r):-1,e=n!==void 0&&n>=0?n:Math.max(h,t.length-1,s.length-1,0);if(!Number.isFinite(e)||e<0)e=0;let c=Array(e+1);for(let w=0;w<=e;w++)if(t[w]!==void 0)c[w]=t[w];else if(s[w]!==void 0)c[w]=s[w];return c}async resolveDependencies(t,s){let i=[];for(let n of s){if(!n)continue;try{let f=await this.container.resolve(n.provider,{scope:n.scope,context:t});i[n.index]=f}catch(f){throw Error(`Failed to resolve dependency at index ${n.index}: ${f instanceof Error?f.message:"Unknown error"}`)}}return i}}class gt{plugins=new Map;installed=new Set;register(t){if(this.plugins.has(t.name))throw Error(`Plugin "${t.name}" is already registered`);this.plugins.set(t.name,t)}async install(t){let s=this.resolveInstallOrder();for(let i of s)await this.plugins.get(i).install(t),this.installed.add(i)}isInstalled(t){return this.installed.has(t)}getPlugin(t){return this.plugins.get(t)}getPluginNames(){return Array.from(this.plugins.keys())}resolveInstallOrder(){let t=new Set,s=new Set,i=[],n=(f,r=[])=>{if(s.has(f)){let e=[...r,f].join(" -> ");throw Error(`Circular dependency detected in plugins: ${e}`)}if(t.has(f))return;s.add(f);let h=this.plugins.get(f);if(!h)throw Error(`Plugin "${f}" is not registered`);if(h.dependencies)for(let e of h.dependencies){if(!this.plugins.has(e))throw Error(`Plugin "${f}" depends on "${e}" which is not registered`);n(e,[...r,f])}s.delete(f),t.add(f),i.push(f)};for(let f of this.plugins.keys())n(f);return i}}class St{hono;metadata;container;validator;errorHandler;compiler;pluginManager;config;compiled=!1;globalMiddleware=[];groupPrefix="";constructor(t){if(this.config={adapter:"hono",title:"Veloce-TS API",version:"1.0.0",docs:!0,...t},this.hono=new tt,this.metadata=new H,this.container=new st,this.validator=new Yt,this.errorHandler=new Jt,this.pluginManager=new gt,this.compiler=new ut(this.hono,this.metadata,this.container,this.validator,this.errorHandler),this.config.cors)if(this.config.cors===!0)this.useCors();else this.useCors(this.config.cors)}include(t){let s=H.getControllerMetadata(t);if(s)this.metadata.registerController(t,s);let i=H.getRouteMethods(t);for(let n of i){let f=H.getRouteMetadata(t.prototype,n),r=H.getParameterMetadata(t.prototype,n),h=H.getDependencyMetadata(t.prototype,n);if(f&&f.method&&f.path!==void 0){let e=s?.prefix||"",c=this.normalizePath(e,f.path);this.metadata.registerRoute({target:t,propertyKey:n,method:f.method,path:c,middleware:[...s?.middleware||[],...f.middleware||[]],parameters:r||f.parameters||[],dependencies:h||f.dependencies||[],responses:f.responses||[],docs:f.docs})}}}get(t,s){this.registerFunctionalRoute("GET",t,s)}post(t,s){this.registerFunctionalRoute("POST",t,s)}put(t,s){this.registerFunctionalRoute("PUT",t,s)}delete(t,s){this.registerFunctionalRoute("DELETE",t,s)}patch(t,s){this.registerFunctionalRoute("PATCH",t,s)}route(t){return new dt(this,t)}group(t,s){let i=this.groupPrefix;this.groupPrefix=this.normalizePath(this.groupPrefix,t),s(),this.groupPrefix=i}registerFunctionalRoute(t,s,i){let n=this.normalizePath(this.groupPrefix,s),f={target:Mt,propertyKey:`${t.toLowerCase()}_${n}`,method:t,path:n,middleware:i.middleware||[],parameters:this.extractParametersFromSchema(i.schema),dependencies:[],responses:i.responses||[],docs:i.docs,handler:i.handler};this.metadata.registerRoute(f)}extractParametersFromSchema(t){let s=[],i=0;if(t?.body)s.push({index:i++,type:"body",schema:t.body,required:!0});if(t?.query)s.push({index:i++,type:"query",schema:t.query,required:!1});if(t?.params)s.push({index:i++,type:"param",schema:t.params,required:!0});if(t?.headers)s.push({index:i++,type:"header",schema:t.headers,required:!1});return s}use(t){this.globalMiddleware.push(t),this.hono.use("*",t)}useCors(t){let s=kt(t);this.use(s)}useRateLimit(t){let s=qt(t);this.use(s)}useCompression(t){let s=vt(t);this.use(s)}usePlugin(t){this.pluginManager.register(t)}getPluginManager(){return this.pluginManager}onError(t){this.errorHandler.setCustomHandler(t)}getErrorHandler(){return this.errorHandler}normalizePath(...t){let s=t.filter((i)=>i!=="").join("/").replace(/\/+/g,"/").replace(/\/$/,"");return s.startsWith("/")?s:`/${s}`}getHono(){return this.hono}getMetadata(){return this.metadata}getContainer(){return this.container}getCompiler(){return this.compiler}getConfig(){return this.config}isCompiled(){return this.compiled}markCompiled(){this.compiled=!0}async compile(){if(this.compiled){console.warn("Routes have already been compiled. Skipping compilation.");return}await this.pluginManager.install(this),this.compiler.compile(),this.compiled=!0}async listen(t,s){if(!this.compiled)await this.compile();return this.createAdapter().listen(t,s)}createAdapter(){let t=this.config.adapter||"hono";switch(t){case"hono":{let{HonoAdapter:s}=bt(ot);return new s(this.hono)}case"express":{let{ExpressAdapter:s}=bt(Zt);return new s(this)}case"native":{let{HonoAdapter:s}=bt(ot);return new s(this.hono)}default:throw Error(`Unknown adapter type: ${t}. Supported adapters: 'hono', 'express', 'native'`)}}}class Mt{}class dt{app;path;constructor(t,s){this.app=t;this.path=s}get(t){return this.app.get(this.path,t),this}post(t){return this.app.post(this.path,t),this}put(t){return this.app.put(this.path,t),this}delete(t){return this.app.delete(this.path,t),this}patch(t){return this.app.patch(this.path,t),this}}function mt(t){let s={docs:!1,cors:!1,...t};return new St(s)}function xs(t,s,i,n){let f=t.getContainer(),r=typeof i==="function"?i:()=>i;f.register(s,{scope:n?.scope||"singleton",factory:r})}function at(t){return new T(t)}async function Hs(t,s){let i=mt(s);await t(i),await i.compile();let n=at(i);return{app:i,client:n}}function js(t){t.getContainer().clear()}export{Hs as setupTestApp,xs as mockDependency,at as createTestClient,mt as createTestApp,js as clearMocks,T as TestClient};export{st as n,Qt as o,Xi as p,Bt as q,nt as r,ft as s,rt as t,et as u,ht as v,ct as w,wt as x,ut as y,gt as z,Vt as A,It as B,St as C,T as D,mt as E,xs as F,at as G,Hs as H,js as I};
3
3
 
4
- //# debugId=C040B3A530BF17EB64756E2164756E21
4
+ //# debugId=941DAE281363925164756E2164756E21