@jucie.io/engine-server 1.0.6 → 1.0.9

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.
package/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
- var St=Object.defineProperty;var re=(t,e)=>()=>(t&&(e=t(t=0)),e);var $t=(t,e)=>{for(var r in e)St(t,r,{get:e[r],enumerable:!0})};async function ut(t){return new Promise(e=>{if(t.method==="GET"||t.method==="HEAD"){e(null);return}let r=t.headers["content-type"]||"",n="";t.on("data",s=>{n+=s.toString()}),t.on("end",()=>{try{r.includes("application/json")?e(n?JSON.parse(n):{}):r.includes("application/x-www-form-urlencoded")?e(Vt(n)):r.includes("multipart/form-data")?e({raw:n}):e(n||null)}catch{e(null)}}),t.on("error",()=>{e(null)})})}function Vt(t){let e={},r=t.split("&");for(let n of r){let[s,o]=n.split("=");if(s){let a=decodeURIComponent(s),i=o?decodeURIComponent(o):"";if(a.endsWith("[]")){let l=a.slice(0,-2);e[l]||(e[l]=[]),e[l].push(i)}else e[a]=i}}return e}function ft(t){let e={};for(let[r,n]of t.entries())if(r.endsWith("[]")||/\[\d*\]$/.test(r)){let s=r.replace(/\[\d*\]$/,"").replace("[]","");e[s]||(e[s]=[]),e[s].push(n)}else e[r]=n;return e}var Te=re(()=>{});var _,Oe,Se=re(()=>{Te();_=class{static create(e){return new this(e)}constructor(e){this.name=e,this.server=null,this.kernel=null,this.log=null,this.hooks=null}async initialize(e,r={},n=null){if(this.kernel=e,this.opts=r,this.log=n,r.middleware&&!Array.isArray(r.middleware))throw new Error("opts.middleware must be an array")}async start(e){throw new Error(`start() must be implemented by ${this.name} adapter`)}async stop(){throw new Error(`stop() must be implemented by ${this.name} adapter`)}getHttpServer(){return this.server}isRunning(){return this.server!==null}async handleRequest(e,r){throw new Error(`handleRequest() must be implemented by ${this.name} adapter`)}createContext(e,r){let n=new URL(e.url||e.originalUrl,`http://${e.headers.host}`);return{req:{method:e.method,url:n.toString(),path:n.pathname,headers:Object.fromEntries(Object.entries(e.headers).map(([s,o])=>[s.toLowerCase(),o])),query:e.query||ft(n.searchParams),body:e.body||null,raw:{req:e,res:r},params:{}},res:r,respond:new Oe}}async sendResponse(e,r,n=!1){let s=r??{type:"text",status:204,headers:{},body:""};if(s.type!=="handled"&&!e.headersSent){if(e.statusCode=s.status??200,s.headers)for(let[o,a]of Object.entries(s.headers))e.setHeader(o.toLowerCase(),a);if(n)return e.end();switch(s.type){case"json":return e.getHeader("content-type")||e.setHeader("content-type","application/json; charset=utf-8"),e.end(JSON.stringify(s.body));case"text":return e.getHeader("content-type")||e.setHeader("content-type","text/plain; charset=utf-8"),e.end(s.body??"");case"html":return e.getHeader("content-type")||e.setHeader("content-type","text/html; charset=utf-8"),e.end(s.body??"");case"file":return await this.serveFile(e,s.path);case"stream":{let o=s.body;if(!o)return e.end();if(typeof o.pipe=="function")return o.pipe(e);if(Symbol.asyncIterator in Object(o)){for await(let a of o)e.write(a)||await new Promise(i=>e.once("drain",i));return e.end()}return e.end(o)}default:return e.end("")}}}async serveFile(e,r){let n=await import("node:fs"),s=await import("node:fs/promises"),o=await import("node:path"),{pipeline:a}=await import("node:stream"),{promisify:i}=await import("node:util"),l=i(a),c={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".eot":"application/vnd.ms-fontobject"};try{let u=await s.stat(r);if(!u.isFile())return e.statusCode=404,e.setHeader("content-type","text/plain; charset=utf-8"),e.end("Not Found");let y=o.extname(r).toLowerCase();e.getHeader("content-type")||e.setHeader("content-type",c[y]??"application/octet-stream"),e.setHeader("content-length",String(u.size));let T=n.createReadStream(r);T.on("error",()=>{e.headersSent||(e.statusCode=404),e.end("Not Found")}),await l(T,e)}catch{e.headersSent||(e.statusCode=404,e.setHeader("content-type","text/plain; charset=utf-8")),e.end("Not Found")}}async handleError(e,r){this.log?.error?.("Request handling error:",r),e.headersSent||(e.statusCode=500,e.setHeader("content-type","text/plain; charset=utf-8"),e.end("Internal Server Error"))}},Oe=class{handled(){return{type:"handled"}}json(e,r=200,n={}){return{type:"json",status:r,headers:n,body:e}}text(e,r=200,n={}){return{type:"text",status:r,headers:n,body:e}}html(e,r=200,n={}){return{type:"html",status:r,headers:n,body:e}}file(e,r=200,n={}){return{type:"file",status:r,headers:n,path:e}}stream(e,r=200,n={}){return{type:"stream",status:r,headers:n,body:e}}redirect(e,r=302,n={}){return{type:"text",status:r,headers:{...n,location:e},body:""}}}});var vt={};$t(vt,{ExpressAdapter:()=>Ne});var Ne,Tt=re(()=>{Se();Ne=class extends _{#n=new Set;constructor(e=null){super("express"),this.express=e,this.app=null}async initialize(e,r={},n=null){if(await super.initialize(e,r,n),!this.express)try{this.express=await import("express"),this.express=this.express.default}catch{throw new Error("Express not installed. Run: npm install express")}if(this.app=this.express(),(!r.middleware||!this.#t(r.middleware))&&(this.app.use(this.express.json()),this.app.use(this.express.urlencoded({extended:!0}))),r.middleware&&Array.isArray(r.middleware)){this.log?.info(`Applying ${r.middleware.length} middleware functions`);for(let[s,o]of r.middleware.entries())try{this.app.use(o),this.log?.debug(`Applied middleware ${s+1}/${r.middleware.length}`)}catch(a){throw new Error(`Failed to apply middleware[${s}]: ${a.message}`)}}}registerKernelHandler(){this.app&&this.app.all("*",async(e,r)=>{await this.handleRequest(e,r)})}getExpressApp(){return this.app}async start({port:e=3e3,host:r="0.0.0.0"}={}){return new Promise((n,s)=>{this.server=this.app.listen(e,r,o=>{o?s(o):(this.server.on("connection",a=>{this.#n.add(a),a.on("close",()=>{this.#n.delete(a)})}),this.log?.info(`Express Server with middleware listening on http://${r}:${e}`),n(this.server))})})}async stop(){if(this.server?.close){for(let e of this.#n)e.destroy();return this.#n.clear(),new Promise(e=>{this.server.close(()=>{this.log?.info("Express Server stopped"),e()})})}}async handleRequest(e,r){try{let n=this.createContext(e,r),s=await this.kernel.handle(n);await this.sendResponse(r,s,e.method==="HEAD")}catch(n){await this.handleError(r,n)}}#t(e){return e.some(r=>{let n=r.name?.toLowerCase()||r.toString().toLowerCase();return n.includes("json")||n.includes("urlencoded")||n.includes("bodyparser")})}}});var br=Object.freeze(Object.create(null));function Le(t,e,r="value"){if(Array.isArray(e)){for(let s of e)if(Fe(t,s))return!0;let n=e.map(Y).join(" | ");throw new TypeError(`${r} must be one of: ${n}. Got ${Y(t)}`)}if(!Fe(t,e))throw new TypeError(`${r} must be ${Y(e)}. Got ${Y(t)}`);return!0}function Fe(t,e){return e===String?typeof t=="string":e===Number?typeof t=="number"&&!isNaN(t):e===Boolean?typeof t=="boolean":e===Symbol?typeof t=="symbol":e===BigInt?typeof t=="bigint":e===Function?typeof t=="function":e===Array?Array.isArray(t):e===Object?t!==null&&typeof t=="object"&&!Array.isArray(t):t instanceof e}function Y(t){return t===String?"String":t===Number?"Number":t===Boolean?"Boolean":t===Array?"Array":t===Object?"Object":t===Function?"Function":t===Date?"Date":t===RegExp?"RegExp":t===Promise?"Promise":t===Map?"Map":t===Set?"Set":t===WeakMap?"WeakMap":t===WeakSet?"WeakSet":t===Symbol?"Symbol":t===BigInt?"BigInt":t===Error?"Error":typeof t=="string"?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="symbol"?"symbol":typeof t=="bigint"?"bigint":typeof t=="function"?"function":Array.isArray(t)?"Array":t===null?"null":t===void 0?"undefined":typeof t=="object"?t.constructor?.name||"Object":"unknown"}function D(t,e="value"){return r=>Le(r,t,e)}var ne=new Map,se=new WeakMap,B=t=>{if(se.has(t))return se.get(t)},w=(t,e=[])=>{let r=e.length>0?D(e,"return value"):null;if(ne.has(t))return console.warn(`Definition type "${t}" already exists`),ne.get(t);let n=(s,o,...a)=>{D(String,"name")(s),D(Function,"factory")(o);let i=(...l)=>{try{let c=[...l,...a],u=o(...c);if(r&&u===void 0)throw new Error(`Factory ${t} must return a value for ${s}`);return r&&r(u),u}catch(c){throw console.error(`Error creating definition "${s}"`,c),c}};return Object.defineProperty(i,"_name",{value:s,enumerable:!1,configurable:!1}),se.set(i,t),i};return ne.set(t,n),n};var Mt=new Set(["__proto__","prototype","constructor"]),Pt=new Set(["use","install","uninstall","relay","state","debug"]),Ue=64,_t=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/;function Ft(t,e="key"){if(Mt.has(t))throw new Error(`Illegal key "${t}" in ${e}`)}function ie(t){if(Ft(t,"namespace"),typeof t!="string")throw new Error(`Namespace must be a string, got ${typeof t}`);if(!_t.test(t))throw new Error(`Invalid namespace "${t}". Must be a valid JS identifier`);if(t.length>Ue)throw new Error(`Namespace "${t}" too long (max ${Ue} chars)`);if(Pt.has(t))throw new Error(`Namespace "${t}" is reserved`);return t}var oe=w("MIDDLEWARE",[Function,Array]),ae=w("ACTIONS",[Object]),le=w("UNINSTALL"),ce=w("INITIALIZE"),he=w("GETTERS",[Object]);var K=class t{static create(e){return new t(e)}#n;#t;#r={MIDDLEWARE:null,GETTERS:null,ACTIONS:null,INITIALIZE:null,UNINSTALL:null};constructor(e){this.#n=e}#e(e,r,n){if(this.#r[e])throw new Error(`${e} already defined for ${this.#n}`);this.#r[e]=n(this.#n,r)}defineMiddleware=e=>this.#e("MIDDLEWARE",e,oe);defineGetters=e=>this.#e("GETTERS",e,he);defineActions=e=>this.#e("ACTIONS",e,ae);defineInitialize=e=>this.#e("INITIALIZE",e,ce);defineUninstall=e=>this.#e("UNINSTALL",e,le);_toArray(){return[this.#r.MIDDLEWARE,this.#r.GETTERS,this.#r.ACTIONS,this.#r.INITIALIZE,this.#r.UNINSTALL].filter(Boolean)}};var H=class t{static#n=new Set;static manifest={name:"base",dependencies:[],version:"1.0.0",description:"Base extension template"};static config=null;static unique=!1;static configure(e={}){return{install:(r,n)=>this.install(r,n),manifest:this.manifest,config:{...this.config||this.manifest.defaults||{},...e},unique:!0,configured:!0}}static install(e,r){try{let{namespace:n}=this.manifest;ie(n);let s=new this;t.#n.add(s),Object.defineProperty(s,"config",{value:Object.freeze({...r}),writable:!1,configurable:!1,enumerable:!1}),Object.defineProperty(s,"context",{get:()=>e(),configurable:!1,enumerable:!1}),Object.defineProperty(s,"useContext",{value:(...a)=>e(...a),writable:!1,configurable:!1,enumerable:!1});let o=K.create(n);if(s.setup){let a={defineActions:l=>o.defineActions(()=>l(e,r)),defineMiddleware:l=>o.defineMiddleware(()=>l(e,r)),defineGetters:l=>o.defineGetters(()=>l(e,r)),defineInitialize:l=>o.defineInitialize(()=>l(e,r)),defineUninstall:l=>o.defineUninstall(()=>l(e,r))},i=s.setup(a);return i?.then?i.then(()=>o._toArray()):o._toArray()}return s.middleware&&o.defineMiddleware(()=>s.middleware(e,r)),s.getters&&o.defineGetters(()=>s.getters(e,r)),s.actions&&o.defineActions(()=>s.actions(e,r)),s.initialize&&o.defineInitialize(()=>s.initialize(e,r)),s.uninstall&&o.defineUninstall(()=>s.uninstall(e,r)),o._toArray()}catch(n){throw n}}};var mn=Symbol("jucie.engine");var Dt=Object.defineProperty,h=(t,e)=>Dt(t,"name",{value:e,configurable:!0}),P=class{type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(t,e,r,n,s,o){this.type=t,this.name=e,this.prefix=r,this.value=n,this.suffix=s,this.modifier=o}hasCustomName(){return this.name!==""&&typeof this.name!="number"}};h(P,"Part");var Bt=/[$_\p{ID_Start}]/u,Ht=/[$_\u200C\u200D\p{ID_Continue}]/u,fe=".*";function He(t,e){return(e?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(t)}h(He,"isASCII");function me(t,e=!1){let r=[],n=0;for(;n<t.length;){let s=t[n],o=h(function(a){if(!e)throw new TypeError(a);r.push({type:"INVALID_CHAR",index:n,value:t[n++]})},"ErrorOrInvalid");if(s==="*"){r.push({type:"ASTERISK",index:n,value:t[n++]});continue}if(s==="+"||s==="?"){r.push({type:"OTHER_MODIFIER",index:n,value:t[n++]});continue}if(s==="\\"){r.push({type:"ESCAPED_CHAR",index:n++,value:t[n++]});continue}if(s==="{"){r.push({type:"OPEN",index:n,value:t[n++]});continue}if(s==="}"){r.push({type:"CLOSE",index:n,value:t[n++]});continue}if(s===":"){let a="",i=n+1;for(;i<t.length;){let l=t.substr(i,1);if(i===n+1&&Bt.test(l)||i!==n+1&&Ht.test(l)){a+=t[i++];continue}break}if(!a){o(`Missing parameter name at ${n}`);continue}r.push({type:"NAME",index:n,value:a}),n=i;continue}if(s==="("){let a=1,i="",l=n+1,c=!1;if(t[l]==="?"){o(`Pattern cannot start with "?" at ${l}`);continue}for(;l<t.length;){if(!He(t[l],!1)){o(`Invalid character '${t[l]}' at ${l}.`),c=!0;break}if(t[l]==="\\"){i+=t[l++]+t[l++];continue}if(t[l]===")"){if(a--,a===0){l++;break}}else if(t[l]==="("&&(a++,t[l+1]!=="?")){o(`Capturing groups are not allowed at ${l}`),c=!0;break}i+=t[l++]}if(c)continue;if(a){o(`Unbalanced pattern at ${n}`);continue}if(!i){o(`Missing pattern at ${n}`);continue}r.push({type:"REGEX",index:n,value:i}),n=l;continue}r.push({type:"CHAR",index:n,value:t[n++]})}return r.push({type:"END",index:n,value:""}),r}h(me,"lexer");function ye(t,e={}){let r=me(t);e.delimiter??="/#?",e.prefixes??="./";let n=`[^${x(e.delimiter)}]+?`,s=[],o=0,a=0,i="",l=new Set,c=h(m=>{if(a<r.length&&r[a].type===m)return r[a++].value},"tryConsume"),u=h(()=>c("OTHER_MODIFIER")??c("ASTERISK"),"tryConsumeModifier"),y=h(m=>{let g=c(m);if(g!==void 0)return g;let{type:b,index:j}=r[a];throw new TypeError(`Unexpected ${b} at ${j}, expected ${m}`)},"mustConsume"),T=h(()=>{let m="",g;for(;g=c("CHAR")??c("ESCAPED_CHAR");)m+=g;return m},"consumeText"),Ot=h(m=>m,"DefaultEncodePart"),V=e.encodePart||Ot,W="",ee=h(m=>{W+=m},"appendToPendingFixedValue"),te=h(()=>{W.length&&(s.push(new P(3,"","",V(W),"",3)),W="")},"maybeAddPartFromPendingFixedValue"),Pe=h((m,g,b,j,O)=>{let C=3;switch(O){case"?":C=1;break;case"*":C=0;break;case"+":C=2;break}if(!g&&!b&&C===3){ee(m);return}if(te(),!g&&!b){if(!m)return;s.push(new P(3,"","",V(m),"",C));return}let E;b?b==="*"?E=fe:E=b:E=n;let U=2;E===n?(U=1,E=""):E===fe&&(U=0,E="");let S;if(g?S=g:b&&(S=o++),l.has(S))throw new TypeError(`Duplicate name '${S}'.`);l.add(S),s.push(new P(U,S,V(m),E,V(j),C))},"addPart");for(;a<r.length;){let m=c("CHAR"),g=c("NAME"),b=c("REGEX");if(!g&&!b&&(b=c("ASTERISK")),g||b){let O=m??"";e.prefixes.indexOf(O)===-1&&(ee(O),O=""),te();let C=u();Pe(O,g,b,"",C);continue}let j=m??c("ESCAPED_CHAR");if(j){ee(j);continue}if(c("OPEN")){let O=T(),C=c("NAME"),E=c("REGEX");!C&&!E&&(E=c("ASTERISK"));let U=T();y("CLOSE");let S=u();Pe(O,C,E,U,S);continue}te(),y("END")}return s}h(ye,"parse");function x(t){return t.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}h(x,"escapeString");function pe(t){return t&&t.ignoreCase?"ui":"u"}h(pe,"flags");function ze(t,e,r){return ge(ye(t,r),e,r)}h(ze,"stringToRegexp");function I(t){switch(t){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}h(I,"modifierToString");function ge(t,e,r={}){r.delimiter??="/#?",r.prefixes??="./",r.sensitive??=!1,r.strict??=!1,r.end??=!0,r.start??=!0,r.endsWith="";let n=r.start?"^":"";for(let i of t){if(i.type===3){i.modifier===3?n+=x(i.value):n+=`(?:${x(i.value)})${I(i.modifier)}`;continue}e&&e.push(i.name);let l=`[^${x(r.delimiter)}]+?`,c=i.value;if(i.type===1?c=l:i.type===0&&(c=fe),!i.prefix.length&&!i.suffix.length){i.modifier===3||i.modifier===1?n+=`(${c})${I(i.modifier)}`:n+=`((?:${c})${I(i.modifier)})`;continue}if(i.modifier===3||i.modifier===1){n+=`(?:${x(i.prefix)}(${c})${x(i.suffix)})`,n+=I(i.modifier);continue}n+=`(?:${x(i.prefix)}`,n+=`((?:${c})(?:`,n+=x(i.suffix),n+=x(i.prefix),n+=`(?:${c}))*)${x(i.suffix)})`,i.modifier===0&&(n+="?")}let s=`[${x(r.endsWith)}]|$`,o=`[${x(r.delimiter)}]`;if(r.end)return r.strict||(n+=`${o}?`),r.endsWith.length?n+=`(?=${s})`:n+="$",new RegExp(n,pe(r));r.strict||(n+=`(?:${o}(?=${s}))?`);let a=!1;if(t.length){let i=t[t.length-1];i.type===3&&i.modifier===3&&(a=r.delimiter.indexOf(i)>-1)}return a||(n+=`(?=${o}|${s})`),new RegExp(n,pe(r))}h(ge,"partsToRegexp");var k={delimiter:"",prefixes:"",sensitive:!0,strict:!0},zt={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Gt={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Ge(t,e){return t.length?t[0]==="/"?!0:!e||t.length<2?!1:(t[0]=="\\"||t[0]=="{")&&t[1]=="/":!1}h(Ge,"isAbsolutePathname");function be(t,e){return t.startsWith(e)?t.substring(e.length,t.length):t}h(be,"maybeStripPrefix");function Ve(t,e){return t.endsWith(e)?t.substr(0,t.length-e.length):t}h(Ve,"maybeStripSuffix");function we(t){return!t||t.length<2?!1:t[0]==="["||(t[0]==="\\"||t[0]==="{")&&t[1]==="["}h(we,"treatAsIPv6Hostname");var We=["ftp","file","http","https","ws","wss"];function xe(t){if(!t)return!0;for(let e of We)if(t.test(e))return!0;return!1}h(xe,"isSpecialScheme");function Ye(t,e){if(t=be(t,"#"),e||t==="")return t;let r=new URL("https://example.com");return r.hash=t,r.hash?r.hash.substring(1,r.hash.length):""}h(Ye,"canonicalizeHash");function Ke(t,e){if(t=be(t,"?"),e||t==="")return t;let r=new URL("https://example.com");return r.search=t,r.search?r.search.substring(1,r.search.length):""}h(Ke,"canonicalizeSearch");function qe(t,e){return e||t===""?t:we(t)?Ce(t):Ae(t)}h(qe,"canonicalizeHostname");function Je(t,e){if(e||t==="")return t;let r=new URL("https://example.com");return r.password=t,r.password}h(Je,"canonicalizePassword");function Ze(t,e){if(e||t==="")return t;let r=new URL("https://example.com");return r.username=t,r.username}h(Ze,"canonicalizeUsername");function Xe(t,e,r){if(r||t==="")return t;if(e&&!We.includes(e))return new URL(`${e}:${t}`).pathname;let n=t[0]=="/";return t=new URL(n?t:"/-"+t,"https://example.com").pathname,n||(t=t.substring(2,t.length)),t}h(Xe,"canonicalizePathname");function Qe(t,e,r){return Ee(e)===t&&(t=""),r||t===""?t:Re(t)}h(Qe,"canonicalizePort");function et(t,e){return t=Ve(t,":"),e||t===""?t:q(t)}h(et,"canonicalizeProtocol");function Ee(t){switch(t){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}h(Ee,"defaultPortForProtocol");function q(t){if(t==="")return t;if(/^[-+.A-Za-z0-9]*$/.test(t))return t.toLowerCase();throw new TypeError(`Invalid protocol '${t}'.`)}h(q,"protocolEncodeCallback");function tt(t){if(t==="")return t;let e=new URL("https://example.com");return e.username=t,e.username}h(tt,"usernameEncodeCallback");function rt(t){if(t==="")return t;let e=new URL("https://example.com");return e.password=t,e.password}h(rt,"passwordEncodeCallback");function Ae(t){if(t==="")return t;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(t))throw new TypeError(`Invalid hostname '${t}'`);let e=new URL("https://example.com");return e.hostname=t,e.hostname}h(Ae,"hostnameEncodeCallback");function Ce(t){if(t==="")return t;if(/[^0-9a-fA-F[\]:]/g.test(t))throw new TypeError(`Invalid IPv6 hostname '${t}'`);return t.toLowerCase()}h(Ce,"ipv6HostnameEncodeCallback");function Re(t){if(t===""||/^[0-9]*$/.test(t)&&parseInt(t)<=65535)return t;throw new TypeError(`Invalid port '${t}'.`)}h(Re,"portEncodeCallback");function nt(t){if(t==="")return t;let e=new URL("https://example.com");return e.pathname=t[0]!=="/"?"/-"+t:t,t[0]!=="/"?e.pathname.substring(2,e.pathname.length):e.pathname}h(nt,"standardURLPathnameEncodeCallback");function st(t){return t===""?t:new URL(`data:${t}`).pathname}h(st,"pathURLPathnameEncodeCallback");function it(t){if(t==="")return t;let e=new URL("https://example.com");return e.search=t,e.search.substring(1,e.search.length)}h(it,"searchEncodeCallback");function ot(t){if(t==="")return t;let e=new URL("https://example.com");return e.hash=t,e.hash.substring(1,e.hash.length)}h(ot,"hashEncodeCallback");var at=class{#n;#t=[];#r={};#e=0;#s=1;#a=0;#o=0;#f=0;#h=0;#p=!1;constructor(t){this.#n=t}get result(){return this.#r}parse(){for(this.#t=me(this.#n,!0);this.#e<this.#t.length;this.#e+=this.#s){if(this.#s=1,this.#t[this.#e].type==="END"){if(this.#o===0){this.#w(),this.#u()?this.#i(9,1):this.#d()?this.#i(8,1):this.#i(7,0);continue}else if(this.#o===2){this.#m(5);continue}this.#i(10,0);break}if(this.#f>0)if(this.#T())this.#f-=1;else continue;if(this.#v()){this.#f+=1;continue}switch(this.#o){case 0:this.#x()&&this.#m(1);break;case 1:if(this.#x()){this.#$();let t=7,e=1;this.#A()?(t=2,e=3):this.#p&&(t=2),this.#i(t,e)}break;case 2:this.#g()?this.#m(3):(this.#b()||this.#d()||this.#u())&&this.#m(5);break;case 3:this.#C()?this.#i(4,1):this.#g()&&this.#i(5,1);break;case 4:this.#g()&&this.#i(5,1);break;case 5:this.#O()?this.#h+=1:this.#S()&&(this.#h-=1),this.#R()&&!this.#h?this.#i(6,1):this.#b()?this.#i(7,0):this.#d()?this.#i(8,1):this.#u()&&this.#i(9,1);break;case 6:this.#b()?this.#i(7,0):this.#d()?this.#i(8,1):this.#u()&&this.#i(9,1);break;case 7:this.#d()?this.#i(8,1):this.#u()&&this.#i(9,1);break;case 8:this.#u()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#r.hostname!==void 0&&this.#r.port===void 0&&(this.#r.port="")}#i(t,e){switch(this.#o){case 0:break;case 1:this.#r.protocol=this.#c();break;case 2:break;case 3:this.#r.username=this.#c();break;case 4:this.#r.password=this.#c();break;case 5:this.#r.hostname=this.#c();break;case 6:this.#r.port=this.#c();break;case 7:this.#r.pathname=this.#c();break;case 8:this.#r.search=this.#c();break;case 9:this.#r.hash=this.#c();break;case 10:break}this.#o!==0&&t!==10&&([1,2,3,4].includes(this.#o)&&[6,7,8,9].includes(t)&&(this.#r.hostname??=""),[1,2,3,4,5,6].includes(this.#o)&&[8,9].includes(t)&&(this.#r.pathname??=this.#p?"/":""),[1,2,3,4,5,6,7].includes(this.#o)&&t===9&&(this.#r.search??="")),this.#E(t,e)}#E(t,e){this.#o=t,this.#a=this.#e+e,this.#e+=e,this.#s=0}#w(){this.#e=this.#a,this.#s=0}#m(t){this.#w(),this.#o=t}#y(t){return t<0&&(t=this.#t.length-t),t<this.#t.length?this.#t[t]:this.#t[this.#t.length-1]}#l(t,e){let r=this.#y(t);return r.value===e&&(r.type==="CHAR"||r.type==="ESCAPED_CHAR"||r.type==="INVALID_CHAR")}#x(){return this.#l(this.#e,":")}#A(){return this.#l(this.#e+1,"/")&&this.#l(this.#e+2,"/")}#g(){return this.#l(this.#e,"@")}#C(){return this.#l(this.#e,":")}#R(){return this.#l(this.#e,":")}#b(){return this.#l(this.#e,"/")}#d(){if(this.#l(this.#e,"?"))return!0;if(this.#t[this.#e].value!=="?")return!1;let t=this.#y(this.#e-1);return t.type!=="NAME"&&t.type!=="REGEX"&&t.type!=="CLOSE"&&t.type!=="ASTERISK"}#u(){return this.#l(this.#e,"#")}#v(){return this.#t[this.#e].type=="OPEN"}#T(){return this.#t[this.#e].type=="CLOSE"}#O(){return this.#l(this.#e,"[")}#S(){return this.#l(this.#e,"]")}#c(){let t=this.#t[this.#e],e=this.#y(this.#a).index;return this.#n.substring(e,t.index)}#$(){let t={};Object.assign(t,k),t.encodePart=q;let e=ze(this.#c(),void 0,t);this.#p=xe(e)}};h(at,"Parser");var ue=["protocol","username","password","hostname","port","pathname","search","hash"],$="*";function de(t,e){if(typeof t!="string")throw new TypeError("parameter 1 is not of type 'string'.");let r=new URL(t,e);return{protocol:r.protocol.substring(0,r.protocol.length-1),username:r.username,password:r.password,hostname:r.hostname,port:r.port,pathname:r.pathname,search:r.search!==""?r.search.substring(1,r.search.length):void 0,hash:r.hash!==""?r.hash.substring(1,r.hash.length):void 0}}h(de,"extractValues");function v(t,e){return e?M(t):t}h(v,"processBaseURLString");function N(t,e,r){let n;if(typeof e.baseURL=="string")try{n=new URL(e.baseURL),e.protocol===void 0&&(t.protocol=v(n.protocol.substring(0,n.protocol.length-1),r)),!r&&e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.username===void 0&&(t.username=v(n.username,r)),!r&&e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.username===void 0&&e.password===void 0&&(t.password=v(n.password,r)),e.protocol===void 0&&e.hostname===void 0&&(t.hostname=v(n.hostname,r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&(t.port=v(n.port,r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&(t.pathname=v(n.pathname,r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&e.search===void 0&&(t.search=v(n.search.substring(1,n.search.length),r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&e.search===void 0&&e.hash===void 0&&(t.hash=v(n.hash.substring(1,n.hash.length),r))}catch{throw new TypeError(`invalid baseURL '${e.baseURL}'.`)}if(typeof e.protocol=="string"&&(t.protocol=et(e.protocol,r)),typeof e.username=="string"&&(t.username=Ze(e.username,r)),typeof e.password=="string"&&(t.password=Je(e.password,r)),typeof e.hostname=="string"&&(t.hostname=qe(e.hostname,r)),typeof e.port=="string"&&(t.port=Qe(e.port,t.protocol,r)),typeof e.pathname=="string"){if(t.pathname=e.pathname,n&&!Ge(t.pathname,r)){let s=n.pathname.lastIndexOf("/");s>=0&&(t.pathname=v(n.pathname.substring(0,s+1),r)+t.pathname)}t.pathname=Xe(t.pathname,t.protocol,r)}return typeof e.search=="string"&&(t.search=Ke(e.search,r)),typeof e.hash=="string"&&(t.hash=Ye(e.hash,r)),t}h(N,"applyInit");function M(t){return t.replace(/([+*?:{}()\\])/g,"\\$1")}h(M,"escapePatternString");function lt(t){return t.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}h(lt,"escapeRegexpString");function ct(t,e){e.delimiter??="/#?",e.prefixes??="./",e.sensitive??=!1,e.strict??=!1,e.end??=!0,e.start??=!0,e.endsWith="";let r=".*",n=`[^${lt(e.delimiter)}]+?`,s=/[$_\u200C\u200D\p{ID_Continue}]/u,o="";for(let a=0;a<t.length;++a){let i=t[a];if(i.type===3){if(i.modifier===3){o+=M(i.value);continue}o+=`{${M(i.value)}}${I(i.modifier)}`;continue}let l=i.hasCustomName(),c=!!i.suffix.length||!!i.prefix.length&&(i.prefix.length!==1||!e.prefixes.includes(i.prefix)),u=a>0?t[a-1]:null,y=a<t.length-1?t[a+1]:null;if(!c&&l&&i.type===1&&i.modifier===3&&y&&!y.prefix.length&&!y.suffix.length)if(y.type===3){let T=y.value.length>0?y.value[0]:"";c=s.test(T)}else c=!y.hasCustomName();if(!c&&!i.prefix.length&&u&&u.type===3){let T=u.value[u.value.length-1];c=e.prefixes.includes(T)}c&&(o+="{"),o+=M(i.prefix),l&&(o+=`:${i.name}`),i.type===2?o+=`(${i.value})`:i.type===1?l||(o+=`(${n})`):i.type===0&&(!l&&(!u||u.type===3||u.modifier!==3||c||i.prefix!=="")?o+="*":o+=`(${r})`),i.type===1&&l&&i.suffix.length&&s.test(i.suffix[0])&&(o+="\\"),o+=M(i.suffix),c&&(o+="}"),i.modifier!==3&&(o+=I(i.modifier))}return o}h(ct,"partsToPattern");var ve=class{#n;#t={};#r={};#e={};#s={};#a=!1;constructor(t={},e,r){try{let n;if(typeof e=="string"?n=e:r=e,typeof t=="string"){let i=new at(t);if(i.parse(),t=i.result,n===void 0&&typeof t.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");t.baseURL=n}else{if(!t||typeof t!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(n)throw new TypeError("parameter 1 is not of type 'string'.")}typeof r>"u"&&(r={ignoreCase:!1});let s={ignoreCase:r.ignoreCase===!0},o={pathname:$,protocol:$,username:$,password:$,hostname:$,port:$,search:$,hash:$};this.#n=N(o,t,!0),Ee(this.#n.protocol)===this.#n.port&&(this.#n.port="");let a;for(a of ue){if(!(a in this.#n))continue;let i={},l=this.#n[a];switch(this.#r[a]=[],a){case"protocol":Object.assign(i,k),i.encodePart=q;break;case"username":Object.assign(i,k),i.encodePart=tt;break;case"password":Object.assign(i,k),i.encodePart=rt;break;case"hostname":Object.assign(i,zt),we(l)?i.encodePart=Ce:i.encodePart=Ae;break;case"port":Object.assign(i,k),i.encodePart=Re;break;case"pathname":xe(this.#t.protocol)?(Object.assign(i,Gt,s),i.encodePart=nt):(Object.assign(i,k,s),i.encodePart=st);break;case"search":Object.assign(i,k,s),i.encodePart=it;break;case"hash":Object.assign(i,k,s),i.encodePart=ot;break}try{this.#s[a]=ye(l,i),this.#t[a]=ge(this.#s[a],this.#r[a],i),this.#e[a]=ct(this.#s[a],i),this.#a=this.#a||this.#s[a].some(c=>c.type===2)}catch{throw new TypeError(`invalid ${a} pattern '${this.#n[a]}'.`)}}}catch(n){throw new TypeError(`Failed to construct 'URLPattern': ${n.message}`)}}get[Symbol.toStringTag](){return"URLPattern"}test(t={},e){let r={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&e)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return!1;try{typeof t=="object"?r=N(r,t,!1):r=N(r,de(t,e),!1)}catch{return!1}let n;for(n of ue)if(!this.#t[n].exec(r[n]))return!1;return!0}exec(t={},e){let r={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&e)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return;try{typeof t=="object"?r=N(r,t,!1):r=N(r,de(t,e),!1)}catch{return null}let n={};e?n.inputs=[t,e]:n.inputs=[t];let s;for(s of ue){let o=this.#t[s].exec(r[s]);if(!o)return null;let a={};for(let[i,l]of this.#r[s].entries())if(typeof l=="string"||typeof l=="number"){let c=o[i+1];a[l]=c}n[s]={input:r[s]??"",groups:a}}return n}static compareComponent(t,e,r){let n=h((i,l)=>{for(let c of["type","modifier","prefix","value","suffix"]){if(i[c]<l[c])return-1;if(i[c]!==l[c])return 1}return 0},"comparePart"),s=new P(3,"","","","",3),o=new P(0,"","","","",3),a=h((i,l)=>{let c=0;for(;c<Math.min(i.length,l.length);++c){let u=n(i[c],l[c]);if(u)return u}return i.length===l.length?0:n(i[c]??s,l[c]??s)},"comparePartList");return!e.#e[t]&&!r.#e[t]?0:e.#e[t]&&!r.#e[t]?a(e.#s[t],[o]):!e.#e[t]&&r.#e[t]?a([o],r.#s[t]):a(e.#s[t],r.#s[t])}get protocol(){return this.#e.protocol}get username(){return this.#e.username}get password(){return this.#e.password}get hostname(){return this.#e.hostname}get port(){return this.#e.port}get pathname(){return this.#e.pathname}get search(){return this.#e.search}get hash(){return this.#e.hash}get hasRegExpGroups(){return this.#a}};h(ve,"URLPattern");globalThis.URLPattern||(globalThis.URLPattern=ve);function ht(t){let e=new URLPattern({pathname:t});return r=>e.exec({pathname:r})?.pathname.groups??null}var J=class{#n=[];#t=[];#r={onRequest:null,preHandler:null,onSend:null,onError:null};#e=null;constructor(){}registerRoutes(e){for(let r of e)this.registerRoute(r)}registerRoute(e){let r={...e,match:ht(e.path)};this.#n.push(r)}setAppHandlers(e=[]){this.#t=Array.isArray(e)?e:[]}async cleanupAppHandlers(){for(let e of this.#t)e?.cleanup&&await e.cleanup();this.#t=[]}hooks(e){Object.assign(this.#r,e)}setStaticFallback(e,r){this.#e={outputDir:e,handler:r}}async handle(e){let r;try{let n=await this.#r.onRequest?.(e);if(n)return r=n,r;for(let i of this.#t)try{if(!i?.match||!i?.handle)continue;if(await i.match(e.req)){let l=await i.handle(e);if(l)return r=l,r}}catch(l){return r=await this.#r.onError?.(e,l)??e.respond.text("Internal Server Error",500),r}let s=null,o=this.#n.find(i=>{if(i.method!==e.req.method)return!1;let l=i.match(e.req.path);return l?(s=l,!0):!1});if(!o){if(this.#e){let i=await this.#e.handler(e,this.#e.outputDir);r=i&&i.status!==404?i:e.respond.text("Not Found",404)}else r=e.respond.text("Not Found",404);return r}e.req.params=s||{};let a=await this.#r.preHandler?.(e,o);if(a)return r=a,r;r=await o.handler(e)}catch(n){r=await this.#r.onError?.(e,n)??e.respond.text("Internal Server Error",500)}finally{await this.#r.onSend?.(e,r)}return r??e.respond.text("",204)}getRoutes(){return this.#n.map(e=>({method:e.method,path:e.path,params:e.params||[],compiled:!0}))}};Se();Te();import Wt from"node:http";var Z=class extends _{#n=new Set;constructor(){super("http")}async initialize(e,r={},n=null){await super.initialize(e,r,n),r.middleware?.length>0&&(n?.warn('Middleware configured but HTTP adapter selected. Consider using adapter: "express" for full middleware support.'),n?.info("HTTP adapter will simulate middleware using hooks for basic compatibility."))}async start({port:e=3e3,host:r="0.0.0.0"}={}){return this.server=Wt.createServer(async(n,s)=>{try{if(this.opts.middleware?.length>0&&!await this.#t(n,s,this.opts.middleware))return;n.body||(n.body=await ut(n));let o=this.createContext(n,s),a=await this.kernel.handle(o);await this.sendResponse(s,a,n.method==="HEAD")}catch(o){await this.handleError(s,o)}}),this.server.on("connection",n=>{this.#n.add(n),n.on("close",()=>{this.#n.delete(n)})}),await new Promise((n,s)=>this.server.listen(e,r,o=>o?s(o):n())),this.log?.info?.(`HTTP Server listening on http://${r}:${e}`),this.server}async stop(){if(this.server){for(let e of this.#n)e.destroy();this.#n.clear(),await new Promise(e=>this.server.close(()=>e())),this.server=null}}async#t(e,r,n){for(let s of n)try{let o=!1,a=i=>{if(i)throw i;o=!0};if(r.json||(r.json=i=>(r.setHeader("Content-Type","application/json"),r.end(JSON.stringify(i)),!1)),await s(e,r,a),!o&&r.headersSent)return!1}catch(o){return this.log?.error(`Middleware simulation error: ${o.message}`),r.statusCode=500,r.end("Internal Server Error"),!1}return!0}};var pt=(t=0)=>e=>`\x1B[${e+t}m`,dt=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,mt=(t=0)=>(e,r,n)=>`\x1B[${38+t};2;${e};${r};${n}m`,p={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Yn=Object.keys(p.modifier),Yt=Object.keys(p.color),Kt=Object.keys(p.bgColor),Kn=[...Yt,...Kt];function qt(){let t=new Map;for(let[e,r]of Object.entries(p)){for(let[n,s]of Object.entries(r))p[n]={open:`\x1B[${s[0]}m`,close:`\x1B[${s[1]}m`},r[n]=p[n],t.set(s[0],s[1]);Object.defineProperty(p,e,{value:r,enumerable:!1})}return Object.defineProperty(p,"codes",{value:t,enumerable:!1}),p.color.close="\x1B[39m",p.bgColor.close="\x1B[49m",p.color.ansi=pt(),p.color.ansi256=dt(),p.color.ansi16m=mt(),p.bgColor.ansi=pt(10),p.bgColor.ansi256=dt(10),p.bgColor.ansi16m=mt(10),Object.defineProperties(p,{rgbToAnsi256:{value(e,r,n){return e===r&&r===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(r/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){let r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!r)return[0,0,0];let[n]=r;n.length===3&&(n=[...n].map(o=>o+o).join(""));let s=Number.parseInt(n,16);return[s>>16&255,s>>8&255,s&255]},enumerable:!1},hexToAnsi256:{value:e=>p.rgbToAnsi256(...p.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let r,n,s;if(e>=232)r=((e-232)*10+8)/255,n=r,s=r;else{e-=16;let i=e%36;r=Math.floor(e/36)/5,n=Math.floor(i/6)/5,s=i%6/5}let o=Math.max(r,n,s)*2;if(o===0)return 30;let a=30+(Math.round(s)<<2|Math.round(n)<<1|Math.round(r));return o===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,r,n)=>p.ansi256ToAnsi(p.rgbToAnsi256(e,r,n)),enumerable:!1},hexToAnsi:{value:e=>p.ansi256ToAnsi(p.hexToAnsi256(e)),enumerable:!1}}),p}var Jt=qt(),R=Jt;import $e from"node:process";import Zt from"node:os";import yt from"node:tty";function A(t,e=globalThis.Deno?globalThis.Deno.args:$e.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",n=e.indexOf(r+t),s=e.indexOf("--");return n!==-1&&(s===-1||n<s)}var{env:d}=$e,X;A("no-color")||A("no-colors")||A("color=false")||A("color=never")?X=0:(A("color")||A("colors")||A("color=true")||A("color=always"))&&(X=1);function Xt(){if("FORCE_COLOR"in d)return d.FORCE_COLOR==="true"?1:d.FORCE_COLOR==="false"?0:d.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(d.FORCE_COLOR,10),3)}function Qt(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function er(t,{streamIsTTY:e,sniffFlags:r=!0}={}){let n=Xt();n!==void 0&&(X=n);let s=r?X:n;if(s===0)return 0;if(r){if(A("color=16m")||A("color=full")||A("color=truecolor"))return 3;if(A("color=256"))return 2}if("TF_BUILD"in d&&"AGENT_NAME"in d)return 1;if(t&&!e&&s===void 0)return 0;let o=s||0;if(d.TERM==="dumb")return o;if($e.platform==="win32"){let a=Zt.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in d)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(a=>a in d)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(a=>a in d)||d.CI_NAME==="codeship"?1:o;if("TEAMCITY_VERSION"in d)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(d.TEAMCITY_VERSION)?1:0;if(d.COLORTERM==="truecolor"||d.TERM==="xterm-kitty"||d.TERM==="xterm-ghostty"||d.TERM==="wezterm")return 3;if("TERM_PROGRAM"in d){let a=Number.parseInt((d.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(d.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(d.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(d.TERM)||"COLORTERM"in d?1:o}function gt(t,e={}){let r=er(t,{streamIsTTY:t&&t.isTTY,...e});return Qt(r)}var tr={stdout:gt({isTTY:yt.isatty(1)}),stderr:gt({isTTY:yt.isatty(2)})},bt=tr;function wt(t,e,r){let n=t.indexOf(e);if(n===-1)return t;let s=e.length,o=0,a="";do a+=t.slice(o,n)+e+r,o=n+s,n=t.indexOf(e,o);while(n!==-1);return a+=t.slice(o),a}function xt(t,e,r,n){let s=0,o="";do{let a=t[n-1]==="\r";o+=t.slice(s,a?n-1:n)+e+(a?`\r
1
+ var wt=Object.defineProperty;var Z=(t,e)=>()=>(t&&(e=t(t=0)),e);var xt=(t,e)=>{for(var r in e)wt(t,r,{get:e[r],enumerable:!0})};async function Ae(t){return new Promise(e=>{if(t.method==="GET"||t.method==="HEAD"){e(null);return}let r=t.headers["content-type"]||"",s="";t.on("data",o=>{s+=o.toString()}),t.on("end",()=>{try{r.includes("application/json")?e(s?JSON.parse(s):{}):r.includes("application/x-www-form-urlencoded")?e(vt(s)):r.includes("multipart/form-data")?e({raw:s}):e(s||null)}catch{e(null)}}),t.on("error",()=>{e(null)})})}function vt(t){let e={},r=t.split("&");for(let s of r){let[o,i]=s.split("=");if(o){let a=decodeURIComponent(o),n=i?decodeURIComponent(i):"";if(a.endsWith("[]")){let l=a.slice(0,-2);e[l]||(e[l]=[]),e[l].push(n)}else e[a]=n}}return e}function $e(t){let e={};for(let[r,s]of t.entries())if(r.endsWith("[]")||/\[\d*\]$/.test(r)){let o=r.replace(/\[\d*\]$/,"").replace("[]","");e[o]||(e[o]=[]),e[o].push(s)}else e[r]=s;return e}var ee=Z(()=>{});var I,ke,Oe,Pe,V,te=Z(()=>{ee();I=class{static create(e){return new this(e)}constructor(e){this.name=e,this.server=null,this.kernel=null,this.log=null,this.hooks=null}async initialize(e,r={},s=null){if(this.kernel=e,this.opts=r,this.log=s,r.middleware&&!Array.isArray(r.middleware))throw new Error("opts.middleware must be an array")}async start(e){throw new Error(`start() must be implemented by ${this.name} adapter`)}async stop(){throw new Error(`stop() must be implemented by ${this.name} adapter`)}getHttpServer(){return this.server}isRunning(){return this.server!==null}async handleRequest(e,r){throw new Error(`handleRequest() must be implemented by ${this.name} adapter`)}createContext(e,r){let s=new URL(e.url||e.originalUrl,`http://${e.headers.host}`);return{req:{method:e.method,url:s.toString(),path:s.pathname,headers:Object.fromEntries(Object.entries(e.headers).map(([o,i])=>[o.toLowerCase(),i])),query:e.query||$e(s.searchParams),body:e.body||null,raw:{req:e,res:r},params:{}},res:r,respond:new V}}async sendResponse(e,r,s=!1){let o=r??{type:"text",status:204,headers:{},body:""};if(o.type!=="handled"&&!e.headersSent){if(e.statusCode=o.status??200,o.headers)for(let[i,a]of Object.entries(o.headers))e.setHeader(i.toLowerCase(),a);if(s)return e.end();switch(o.type){case"json":return e.getHeader("content-type")||e.setHeader("content-type","application/json; charset=utf-8"),e.end(JSON.stringify(o.body));case"text":return e.getHeader("content-type")||e.setHeader("content-type","text/plain; charset=utf-8"),e.end(o.body??"");case"html":return e.getHeader("content-type")||e.setHeader("content-type","text/html; charset=utf-8"),e.end(o.body??"");case"file":return await this.serveFile(e,o.path);case"stream":{let i=o.body;if(!i)return e.end();if(typeof i.pipe=="function")return i.pipe(e);if(Symbol.asyncIterator in Object(i)){for await(let a of i)e.write(a)||await new Promise(n=>e.once("drain",n));return e.end()}return e.end(i)}default:return e.end("")}}}async serveFile(e,r){let s=await import("node:fs"),o=await import("node:fs/promises"),i=await import("node:path"),{pipeline:a}=await import("node:stream"),{promisify:n}=await import("node:util"),l=n(a),h={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".mjs":"application/javascript; charset=utf-8",".json":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".eot":"application/vnd.ms-fontobject"};try{let u=await o.stat(r);if(!u.isFile())return e.statusCode=404,e.setHeader("content-type","text/plain; charset=utf-8"),e.end("Not Found");let m=i.extname(r).toLowerCase();e.getHeader("content-type")||e.setHeader("content-type",h[m]??"application/octet-stream"),e.setHeader("content-length",String(u.size));let y=s.createReadStream(r);y.on("error",()=>{e.headersSent||(e.statusCode=404),e.end("Not Found")}),await l(y,e)}catch{e.headersSent||(e.statusCode=404,e.setHeader("content-type","text/plain; charset=utf-8")),e.end("Not Found")}}async handleError(e,r){this.log?.error?.("Request handling error:",r),e.headersSent||(e.statusCode=500,e.setHeader("content-type","text/plain; charset=utf-8"),e.end("Internal Server Error"))}},ke=class{constructor(e,r,s,o={}){this.method=e.toUpperCase(),this.path=r,this.handler=s,this.options=o,this.params=o.params||[]}},Oe=class{constructor(){this.onRequest=null,this.preHandler=null,this.onSend=null,this.onError=null}},Pe=class{constructor(e,r,s,o){this.req=e,this.res=r,this.state=s,this.cache=o,this.respond=new V}},V=class{handled(){return{type:"handled"}}json(e,r=200,s={}){return{type:"json",status:r,headers:s,body:e}}text(e,r=200,s={}){return{type:"text",status:r,headers:s,body:e}}html(e,r=200,s={}){return{type:"html",status:r,headers:s,body:e}}file(e,r=200,s={}){return{type:"file",status:r,headers:s,path:e}}stream(e,r=200,s={}){return{type:"stream",status:r,headers:s,body:e}}redirect(e,r=302,s={}){return{type:"text",status:r,headers:{...s,location:e},body:""}}}});var je={};xt(je,{ExpressAdapter:()=>re});var re,Ie=Z(()=>{te();re=class extends I{#s=new Set;constructor(e=null){super("express"),this.express=e,this.app=null}async initialize(e,r={},s=null){if(await super.initialize(e,r,s),!this.express)try{this.express=await import("express"),this.express=this.express.default}catch{throw new Error("Express not installed. Run: npm install express")}if(this.app=this.express(),(!r.middleware||!this.#t(r.middleware))&&(this.app.use(this.express.json()),this.app.use(this.express.urlencoded({extended:!0}))),r.middleware&&Array.isArray(r.middleware)){this.log?.info(`Applying ${r.middleware.length} middleware functions`);for(let[o,i]of r.middleware.entries())try{this.app.use(i),this.log?.debug(`Applied middleware ${o+1}/${r.middleware.length}`)}catch(a){throw new Error(`Failed to apply middleware[${o}]: ${a.message}`)}}}registerKernelHandler(){this.app&&this.app.all("*",async(e,r)=>{await this.handleRequest(e,r)})}getExpressApp(){return this.app}async start({port:e=3e3,host:r="0.0.0.0"}={}){return new Promise((s,o)=>{this.server=this.app.listen(e,r,i=>{i?o(i):(this.server.on("connection",a=>{this.#s.add(a),a.on("close",()=>{this.#s.delete(a)})}),this.log?.info(`Express Server with middleware listening on http://${r}:${e}`),s(this.server))})})}async stop(){if(this.server?.close){for(let e of this.#s)e.destroy();return this.#s.clear(),new Promise(e=>{this.server.close(()=>{this.log?.info("Express Server stopped"),e()})})}}async handleRequest(e,r){try{let s=this.createContext(e,r),o=await this.kernel.handle(s);await this.sendResponse(r,o,e.method==="HEAD")}catch(s){await this.handleError(r,s)}}#t(e){return e.some(r=>{let s=r.name?.toLowerCase()||r.toString().toLowerCase();return s.includes("json")||s.includes("urlencoded")||s.includes("bodyparser")})}}});var Rt=Object.defineProperty,c=(t,e)=>Rt(t,"name",{value:e,configurable:!0}),N=class{type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(t,e,r,s,o,i){this.type=t,this.name=e,this.prefix=r,this.value=s,this.suffix=o,this.modifier=i}hasCustomName(){return this.name!==""&&typeof this.name!="number"}};c(N,"Part");var Et=/[$_\p{ID_Start}]/u,Ct=/[$_\u200C\u200D\p{ID_Continue}]/u,se=".*";function Ne(t,e){return(e?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(t)}c(Ne,"isASCII");function ne(t,e=!1){let r=[],s=0;for(;s<t.length;){let o=t[s],i=c(function(a){if(!e)throw new TypeError(a);r.push({type:"INVALID_CHAR",index:s,value:t[s++]})},"ErrorOrInvalid");if(o==="*"){r.push({type:"ASTERISK",index:s,value:t[s++]});continue}if(o==="+"||o==="?"){r.push({type:"OTHER_MODIFIER",index:s,value:t[s++]});continue}if(o==="\\"){r.push({type:"ESCAPED_CHAR",index:s++,value:t[s++]});continue}if(o==="{"){r.push({type:"OPEN",index:s,value:t[s++]});continue}if(o==="}"){r.push({type:"CLOSE",index:s,value:t[s++]});continue}if(o===":"){let a="",n=s+1;for(;n<t.length;){let l=t.substr(n,1);if(n===s+1&&Et.test(l)||n!==s+1&&Ct.test(l)){a+=t[n++];continue}break}if(!a){i(`Missing parameter name at ${s}`);continue}r.push({type:"NAME",index:s,value:a}),s=n;continue}if(o==="("){let a=1,n="",l=s+1,h=!1;if(t[l]==="?"){i(`Pattern cannot start with "?" at ${l}`);continue}for(;l<t.length;){if(!Ne(t[l],!1)){i(`Invalid character '${t[l]}' at ${l}.`),h=!0;break}if(t[l]==="\\"){n+=t[l++]+t[l++];continue}if(t[l]===")"){if(a--,a===0){l++;break}}else if(t[l]==="("&&(a++,t[l+1]!=="?")){i(`Capturing groups are not allowed at ${l}`),h=!0;break}n+=t[l++]}if(h)continue;if(a){i(`Unbalanced pattern at ${s}`);continue}if(!n){i(`Missing pattern at ${s}`);continue}r.push({type:"REGEX",index:s,value:n}),s=l;continue}r.push({type:"CHAR",index:s,value:t[s++]})}return r.push({type:"END",index:s,value:""}),r}c(ne,"lexer");function oe(t,e={}){let r=ne(t);e.delimiter??="/#?",e.prefixes??="./";let s=`[^${x(e.delimiter)}]+?`,o=[],i=0,a=0,n="",l=new Set,h=c(g=>{if(a<r.length&&r[a].type===g)return r[a++].value},"tryConsume"),u=c(()=>h("OTHER_MODIFIER")??h("ASTERISK"),"tryConsumeModifier"),m=c(g=>{let b=h(g);if(b!==void 0)return b;let{type:w,index:j}=r[a];throw new TypeError(`Unexpected ${w} at ${j}, expected ${g}`)},"mustConsume"),y=c(()=>{let g="",b;for(;b=h("CHAR")??h("ESCAPED_CHAR");)g+=b;return g},"consumeText"),G=c(g=>g,"DefaultEncodePart"),P=e.encodePart||G,z="",J=c(g=>{z+=g},"appendToPendingFixedValue"),Q=c(()=>{z.length&&(o.push(new N(3,"","",P(z),"",3)),z="")},"maybeAddPartFromPendingFixedValue"),Se=c((g,b,w,j,S)=>{let E=3;switch(S){case"?":E=1;break;case"*":E=0;break;case"+":E=2;break}if(!b&&!w&&E===3){J(g);return}if(Q(),!b&&!w){if(!g)return;o.push(new N(3,"","",P(g),"",E));return}let v;w?w==="*"?v=se:v=w:v=s;let U=2;v===s?(U=1,v=""):v===se&&(U=0,v="");let A;if(b?A=b:w&&(A=i++),l.has(A))throw new TypeError(`Duplicate name '${A}'.`);l.add(A),o.push(new N(U,A,P(g),v,P(j),E))},"addPart");for(;a<r.length;){let g=h("CHAR"),b=h("NAME"),w=h("REGEX");if(!b&&!w&&(w=h("ASTERISK")),b||w){let S=g??"";e.prefixes.indexOf(S)===-1&&(J(S),S=""),Q();let E=u();Se(S,b,w,"",E);continue}let j=g??h("ESCAPED_CHAR");if(j){J(j);continue}if(h("OPEN")){let S=y(),E=h("NAME"),v=h("REGEX");!E&&!v&&(v=h("ASTERISK"));let U=y();m("CLOSE");let A=u();Se(S,E,v,U,A);continue}Q(),m("END")}return o}c(oe,"parse");function x(t){return t.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}c(x,"escapeString");function ie(t){return t&&t.ignoreCase?"ui":"u"}c(ie,"flags");function Le(t,e,r){return ae(oe(t,r),e,r)}c(Le,"stringToRegexp");function O(t){switch(t){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}c(O,"modifierToString");function ae(t,e,r={}){r.delimiter??="/#?",r.prefixes??="./",r.sensitive??=!1,r.strict??=!1,r.end??=!0,r.start??=!0,r.endsWith="";let s=r.start?"^":"";for(let n of t){if(n.type===3){n.modifier===3?s+=x(n.value):s+=`(?:${x(n.value)})${O(n.modifier)}`;continue}e&&e.push(n.name);let l=`[^${x(r.delimiter)}]+?`,h=n.value;if(n.type===1?h=l:n.type===0&&(h=se),!n.prefix.length&&!n.suffix.length){n.modifier===3||n.modifier===1?s+=`(${h})${O(n.modifier)}`:s+=`((?:${h})${O(n.modifier)})`;continue}if(n.modifier===3||n.modifier===1){s+=`(?:${x(n.prefix)}(${h})${x(n.suffix)})`,s+=O(n.modifier);continue}s+=`(?:${x(n.prefix)}`,s+=`((?:${h})(?:`,s+=x(n.suffix),s+=x(n.prefix),s+=`(?:${h}))*)${x(n.suffix)})`,n.modifier===0&&(s+="?")}let o=`[${x(r.endsWith)}]|$`,i=`[${x(r.delimiter)}]`;if(r.end)return r.strict||(s+=`${i}?`),r.endsWith.length?s+=`(?=${o})`:s+="$",new RegExp(s,ie(r));r.strict||(s+=`(?:${i}(?=${o}))?`);let a=!1;if(t.length){let n=t[t.length-1];n.type===3&&n.modifier===3&&(a=r.delimiter.indexOf(n)>-1)}return a||(s+=`(?=${i}|${o})`),new RegExp(s,ie(r))}c(ae,"partsToRegexp");var $={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Tt={delimiter:".",prefixes:"",sensitive:!0,strict:!0},St={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Fe(t,e){return t.length?t[0]==="/"?!0:!e||t.length<2?!1:(t[0]=="\\"||t[0]=="{")&&t[1]=="/":!1}c(Fe,"isAbsolutePathname");function le(t,e){return t.startsWith(e)?t.substring(e.length,t.length):t}c(le,"maybeStripPrefix");function Me(t,e){return t.endsWith(e)?t.substr(0,t.length-e.length):t}c(Me,"maybeStripSuffix");function he(t){return!t||t.length<2?!1:t[0]==="["||(t[0]==="\\"||t[0]==="{")&&t[1]==="["}c(he,"treatAsIPv6Hostname");var He=["ftp","file","http","https","ws","wss"];function ce(t){if(!t)return!0;for(let e of He)if(t.test(e))return!0;return!1}c(ce,"isSpecialScheme");function Ue(t,e){if(t=le(t,"#"),e||t==="")return t;let r=new URL("https://example.com");return r.hash=t,r.hash?r.hash.substring(1,r.hash.length):""}c(Ue,"canonicalizeHash");function Be(t,e){if(t=le(t,"?"),e||t==="")return t;let r=new URL("https://example.com");return r.search=t,r.search?r.search.substring(1,r.search.length):""}c(Be,"canonicalizeSearch");function _e(t,e){return e||t===""?t:he(t)?fe(t):pe(t)}c(_e,"canonicalizeHostname");function De(t,e){if(e||t==="")return t;let r=new URL("https://example.com");return r.password=t,r.password}c(De,"canonicalizePassword");function Ge(t,e){if(e||t==="")return t;let r=new URL("https://example.com");return r.username=t,r.username}c(Ge,"canonicalizeUsername");function ze(t,e,r){if(r||t==="")return t;if(e&&!He.includes(e))return new URL(`${e}:${t}`).pathname;let s=t[0]=="/";return t=new URL(s?t:"/-"+t,"https://example.com").pathname,s||(t=t.substring(2,t.length)),t}c(ze,"canonicalizePathname");function Ve(t,e,r){return ue(e)===t&&(t=""),r||t===""?t:de(t)}c(Ve,"canonicalizePort");function Ke(t,e){return t=Me(t,":"),e||t===""?t:K(t)}c(Ke,"canonicalizeProtocol");function ue(t){switch(t){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}c(ue,"defaultPortForProtocol");function K(t){if(t==="")return t;if(/^[-+.A-Za-z0-9]*$/.test(t))return t.toLowerCase();throw new TypeError(`Invalid protocol '${t}'.`)}c(K,"protocolEncodeCallback");function We(t){if(t==="")return t;let e=new URL("https://example.com");return e.username=t,e.username}c(We,"usernameEncodeCallback");function Ye(t){if(t==="")return t;let e=new URL("https://example.com");return e.password=t,e.password}c(Ye,"passwordEncodeCallback");function pe(t){if(t==="")return t;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(t))throw new TypeError(`Invalid hostname '${t}'`);let e=new URL("https://example.com");return e.hostname=t,e.hostname}c(pe,"hostnameEncodeCallback");function fe(t){if(t==="")return t;if(/[^0-9a-fA-F[\]:]/g.test(t))throw new TypeError(`Invalid IPv6 hostname '${t}'`);return t.toLowerCase()}c(fe,"ipv6HostnameEncodeCallback");function de(t){if(t===""||/^[0-9]*$/.test(t)&&parseInt(t)<=65535)return t;throw new TypeError(`Invalid port '${t}'.`)}c(de,"portEncodeCallback");function qe(t){if(t==="")return t;let e=new URL("https://example.com");return e.pathname=t[0]!=="/"?"/-"+t:t,t[0]!=="/"?e.pathname.substring(2,e.pathname.length):e.pathname}c(qe,"standardURLPathnameEncodeCallback");function Xe(t){return t===""?t:new URL(`data:${t}`).pathname}c(Xe,"pathURLPathnameEncodeCallback");function Je(t){if(t==="")return t;let e=new URL("https://example.com");return e.search=t,e.search.substring(1,e.search.length)}c(Je,"searchEncodeCallback");function Qe(t){if(t==="")return t;let e=new URL("https://example.com");return e.hash=t,e.hash.substring(1,e.hash.length)}c(Qe,"hashEncodeCallback");var Ze=class{#s;#t=[];#r={};#e=0;#n=1;#a=0;#i=0;#p=0;#c=0;#f=!1;constructor(t){this.#s=t}get result(){return this.#r}parse(){for(this.#t=ne(this.#s,!0);this.#e<this.#t.length;this.#e+=this.#n){if(this.#n=1,this.#t[this.#e].type==="END"){if(this.#i===0){this.#w(),this.#u()?this.#o(9,1):this.#d()?this.#o(8,1):this.#o(7,0);continue}else if(this.#i===2){this.#m(5);continue}this.#o(10,0);break}if(this.#p>0)if(this.#S())this.#p-=1;else continue;if(this.#T()){this.#p+=1;continue}switch(this.#i){case 0:this.#x()&&this.#m(1);break;case 1:if(this.#x()){this.#k();let t=7,e=1;this.#R()?(t=2,e=3):this.#f&&(t=2),this.#o(t,e)}break;case 2:this.#y()?this.#m(3):(this.#b()||this.#d()||this.#u())&&this.#m(5);break;case 3:this.#E()?this.#o(4,1):this.#y()&&this.#o(5,1);break;case 4:this.#y()&&this.#o(5,1);break;case 5:this.#A()?this.#c+=1:this.#$()&&(this.#c-=1),this.#C()&&!this.#c?this.#o(6,1):this.#b()?this.#o(7,0):this.#d()?this.#o(8,1):this.#u()&&this.#o(9,1);break;case 6:this.#b()?this.#o(7,0):this.#d()?this.#o(8,1):this.#u()&&this.#o(9,1);break;case 7:this.#d()?this.#o(8,1):this.#u()&&this.#o(9,1);break;case 8:this.#u()&&this.#o(9,1);break;case 9:break;case 10:break}}this.#r.hostname!==void 0&&this.#r.port===void 0&&(this.#r.port="")}#o(t,e){switch(this.#i){case 0:break;case 1:this.#r.protocol=this.#h();break;case 2:break;case 3:this.#r.username=this.#h();break;case 4:this.#r.password=this.#h();break;case 5:this.#r.hostname=this.#h();break;case 6:this.#r.port=this.#h();break;case 7:this.#r.pathname=this.#h();break;case 8:this.#r.search=this.#h();break;case 9:this.#r.hash=this.#h();break;case 10:break}this.#i!==0&&t!==10&&([1,2,3,4].includes(this.#i)&&[6,7,8,9].includes(t)&&(this.#r.hostname??=""),[1,2,3,4,5,6].includes(this.#i)&&[8,9].includes(t)&&(this.#r.pathname??=this.#f?"/":""),[1,2,3,4,5,6,7].includes(this.#i)&&t===9&&(this.#r.search??="")),this.#v(t,e)}#v(t,e){this.#i=t,this.#a=this.#e+e,this.#e+=e,this.#n=0}#w(){this.#e=this.#a,this.#n=0}#m(t){this.#w(),this.#i=t}#g(t){return t<0&&(t=this.#t.length-t),t<this.#t.length?this.#t[t]:this.#t[this.#t.length-1]}#l(t,e){let r=this.#g(t);return r.value===e&&(r.type==="CHAR"||r.type==="ESCAPED_CHAR"||r.type==="INVALID_CHAR")}#x(){return this.#l(this.#e,":")}#R(){return this.#l(this.#e+1,"/")&&this.#l(this.#e+2,"/")}#y(){return this.#l(this.#e,"@")}#E(){return this.#l(this.#e,":")}#C(){return this.#l(this.#e,":")}#b(){return this.#l(this.#e,"/")}#d(){if(this.#l(this.#e,"?"))return!0;if(this.#t[this.#e].value!=="?")return!1;let t=this.#g(this.#e-1);return t.type!=="NAME"&&t.type!=="REGEX"&&t.type!=="CLOSE"&&t.type!=="ASTERISK"}#u(){return this.#l(this.#e,"#")}#T(){return this.#t[this.#e].type=="OPEN"}#S(){return this.#t[this.#e].type=="CLOSE"}#A(){return this.#l(this.#e,"[")}#$(){return this.#l(this.#e,"]")}#h(){let t=this.#t[this.#e],e=this.#g(this.#a).index;return this.#s.substring(e,t.index)}#k(){let t={};Object.assign(t,$),t.encodePart=K;let e=Le(this.#h(),void 0,t);this.#f=ce(e)}};c(Ze,"Parser");var me=["protocol","username","password","hostname","port","pathname","search","hash"],k="*";function ge(t,e){if(typeof t!="string")throw new TypeError("parameter 1 is not of type 'string'.");let r=new URL(t,e);return{protocol:r.protocol.substring(0,r.protocol.length-1),username:r.username,password:r.password,hostname:r.hostname,port:r.port,pathname:r.pathname,search:r.search!==""?r.search.substring(1,r.search.length):void 0,hash:r.hash!==""?r.hash.substring(1,r.hash.length):void 0}}c(ge,"extractValues");function T(t,e){return e?F(t):t}c(T,"processBaseURLString");function L(t,e,r){let s;if(typeof e.baseURL=="string")try{s=new URL(e.baseURL),e.protocol===void 0&&(t.protocol=T(s.protocol.substring(0,s.protocol.length-1),r)),!r&&e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.username===void 0&&(t.username=T(s.username,r)),!r&&e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.username===void 0&&e.password===void 0&&(t.password=T(s.password,r)),e.protocol===void 0&&e.hostname===void 0&&(t.hostname=T(s.hostname,r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&(t.port=T(s.port,r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&(t.pathname=T(s.pathname,r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&e.search===void 0&&(t.search=T(s.search.substring(1,s.search.length),r)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&e.search===void 0&&e.hash===void 0&&(t.hash=T(s.hash.substring(1,s.hash.length),r))}catch{throw new TypeError(`invalid baseURL '${e.baseURL}'.`)}if(typeof e.protocol=="string"&&(t.protocol=Ke(e.protocol,r)),typeof e.username=="string"&&(t.username=Ge(e.username,r)),typeof e.password=="string"&&(t.password=De(e.password,r)),typeof e.hostname=="string"&&(t.hostname=_e(e.hostname,r)),typeof e.port=="string"&&(t.port=Ve(e.port,t.protocol,r)),typeof e.pathname=="string"){if(t.pathname=e.pathname,s&&!Fe(t.pathname,r)){let o=s.pathname.lastIndexOf("/");o>=0&&(t.pathname=T(s.pathname.substring(0,o+1),r)+t.pathname)}t.pathname=ze(t.pathname,t.protocol,r)}return typeof e.search=="string"&&(t.search=Be(e.search,r)),typeof e.hash=="string"&&(t.hash=Ue(e.hash,r)),t}c(L,"applyInit");function F(t){return t.replace(/([+*?:{}()\\])/g,"\\$1")}c(F,"escapePatternString");function et(t){return t.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}c(et,"escapeRegexpString");function tt(t,e){e.delimiter??="/#?",e.prefixes??="./",e.sensitive??=!1,e.strict??=!1,e.end??=!0,e.start??=!0,e.endsWith="";let r=".*",s=`[^${et(e.delimiter)}]+?`,o=/[$_\u200C\u200D\p{ID_Continue}]/u,i="";for(let a=0;a<t.length;++a){let n=t[a];if(n.type===3){if(n.modifier===3){i+=F(n.value);continue}i+=`{${F(n.value)}}${O(n.modifier)}`;continue}let l=n.hasCustomName(),h=!!n.suffix.length||!!n.prefix.length&&(n.prefix.length!==1||!e.prefixes.includes(n.prefix)),u=a>0?t[a-1]:null,m=a<t.length-1?t[a+1]:null;if(!h&&l&&n.type===1&&n.modifier===3&&m&&!m.prefix.length&&!m.suffix.length)if(m.type===3){let y=m.value.length>0?m.value[0]:"";h=o.test(y)}else h=!m.hasCustomName();if(!h&&!n.prefix.length&&u&&u.type===3){let y=u.value[u.value.length-1];h=e.prefixes.includes(y)}h&&(i+="{"),i+=F(n.prefix),l&&(i+=`:${n.name}`),n.type===2?i+=`(${n.value})`:n.type===1?l||(i+=`(${s})`):n.type===0&&(!l&&(!u||u.type===3||u.modifier!==3||h||n.prefix!=="")?i+="*":i+=`(${r})`),n.type===1&&l&&n.suffix.length&&o.test(n.suffix[0])&&(i+="\\"),i+=F(n.suffix),h&&(i+="}"),n.modifier!==3&&(i+=O(n.modifier))}return i}c(tt,"partsToPattern");var B=class{#s;#t={};#r={};#e={};#n={};#a=!1;constructor(t={},e,r){try{let s;if(typeof e=="string"?s=e:r=e,typeof t=="string"){let n=new Ze(t);if(n.parse(),t=n.result,s===void 0&&typeof t.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");t.baseURL=s}else{if(!t||typeof t!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(s)throw new TypeError("parameter 1 is not of type 'string'.")}typeof r>"u"&&(r={ignoreCase:!1});let o={ignoreCase:r.ignoreCase===!0},i={pathname:k,protocol:k,username:k,password:k,hostname:k,port:k,search:k,hash:k};this.#s=L(i,t,!0),ue(this.#s.protocol)===this.#s.port&&(this.#s.port="");let a;for(a of me){if(!(a in this.#s))continue;let n={},l=this.#s[a];switch(this.#r[a]=[],a){case"protocol":Object.assign(n,$),n.encodePart=K;break;case"username":Object.assign(n,$),n.encodePart=We;break;case"password":Object.assign(n,$),n.encodePart=Ye;break;case"hostname":Object.assign(n,Tt),he(l)?n.encodePart=fe:n.encodePart=pe;break;case"port":Object.assign(n,$),n.encodePart=de;break;case"pathname":ce(this.#t.protocol)?(Object.assign(n,St,o),n.encodePart=qe):(Object.assign(n,$,o),n.encodePart=Xe);break;case"search":Object.assign(n,$,o),n.encodePart=Je;break;case"hash":Object.assign(n,$,o),n.encodePart=Qe;break}try{this.#n[a]=oe(l,n),this.#t[a]=ae(this.#n[a],this.#r[a],n),this.#e[a]=tt(this.#n[a],n),this.#a=this.#a||this.#n[a].some(h=>h.type===2)}catch{throw new TypeError(`invalid ${a} pattern '${this.#s[a]}'.`)}}}catch(s){throw new TypeError(`Failed to construct 'URLPattern': ${s.message}`)}}get[Symbol.toStringTag](){return"URLPattern"}test(t={},e){let r={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&e)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return!1;try{typeof t=="object"?r=L(r,t,!1):r=L(r,ge(t,e),!1)}catch{return!1}let s;for(s of me)if(!this.#t[s].exec(r[s]))return!1;return!0}exec(t={},e){let r={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&e)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return;try{typeof t=="object"?r=L(r,t,!1):r=L(r,ge(t,e),!1)}catch{return null}let s={};e?s.inputs=[t,e]:s.inputs=[t];let o;for(o of me){let i=this.#t[o].exec(r[o]);if(!i)return null;let a={};for(let[n,l]of this.#r[o].entries())if(typeof l=="string"||typeof l=="number"){let h=i[n+1];a[l]=h}s[o]={input:r[o]??"",groups:a}}return s}static compareComponent(t,e,r){let s=c((n,l)=>{for(let h of["type","modifier","prefix","value","suffix"]){if(n[h]<l[h])return-1;if(n[h]!==l[h])return 1}return 0},"comparePart"),o=new N(3,"","","","",3),i=new N(0,"","","","",3),a=c((n,l)=>{let h=0;for(;h<Math.min(n.length,l.length);++h){let u=s(n[h],l[h]);if(u)return u}return n.length===l.length?0:s(n[h]??o,l[h]??o)},"comparePartList");return!e.#e[t]&&!r.#e[t]?0:e.#e[t]&&!r.#e[t]?a(e.#n[t],[i]):!e.#e[t]&&r.#e[t]?a([i],r.#n[t]):a(e.#n[t],r.#n[t])}get protocol(){return this.#e.protocol}get username(){return this.#e.username}get password(){return this.#e.password}get hostname(){return this.#e.hostname}get port(){return this.#e.port}get pathname(){return this.#e.pathname}get search(){return this.#e.search}get hash(){return this.#e.hash}get hasRegExpGroups(){return this.#a}};c(B,"URLPattern");globalThis.URLPattern||(globalThis.URLPattern=B);function rt(t){let e=new URLPattern({pathname:t});return r=>e.exec({pathname:r})?.pathname.groups??null}function At(t){let e=/:([a-zA-Z_][a-zA-Z0-9_]*)(\?)?(\*)?/g,r=[],s;for(;(s=e.exec(t))!==null;){let[,o,i,a]=s;r.push({name:o,optional:!!i,splat:!!a,fullMatch:s[0]})}return t.includes("*")&&!t.includes(":*")&&r.push({name:"wild",optional:!1,splat:!0,fullMatch:"*"}),r}function hr(t,e={},r={}){let{strict:s=!0,encode:o=!0,defaultValue:i=""}=r,a=t,n=At(t);for(let l of n){let{name:h,optional:u,fullMatch:m}=l,y=e[h];if(y==null)if(u){a=a.replace(`/${m}`,"").replace(m,"");continue}else{if(s)throw new Error(`Missing required route parameter: ${h}`);y=i}let G=String(y),P=o?encodeURIComponent(G):G;a=a.replace(m,P)}return a=a.replace(/\/+/g,"/"),a}var W=class{#s=[];#t=[];#r={onRequest:null,preHandler:null,onSend:null,onError:null};#e=null;constructor(){}registerRoutes(e){for(let r of e)this.registerRoute(r)}registerRoute(e){let r={...e,match:rt(e.path)};this.#s.push(r)}setAppHandlers(e=[]){this.#t=Array.isArray(e)?e:[]}async cleanupAppHandlers(){for(let e of this.#t)e?.cleanup&&await e.cleanup();this.#t=[]}hooks(e){Object.assign(this.#r,e)}setStaticFallback(e,r){this.#e={outputDir:e,handler:r}}async handle(e){let r;try{let s=await this.#r.onRequest?.(e);if(s)return r=s,r;for(let n of this.#t)try{if(!n?.match||!n?.handle)continue;if(await n.match(e.req)){let l=await n.handle(e);if(l)return r=l,r}}catch(l){return r=await this.#r.onError?.(e,l)??e.respond.text("Internal Server Error",500),r}let o=null,i=this.#s.find(n=>{if(n.method!==e.req.method)return!1;let l=n.match(e.req.path);return l?(o=l,!0):!1});if(!i){if(this.#e){let n=await this.#e.handler(e,this.#e.outputDir);r=n&&n.status!==404?n:e.respond.text("Not Found",404)}else r=e.respond.text("Not Found",404);return r}e.req.params=o||{};let a=await this.#r.preHandler?.(e,i);if(a)return r=a,r;r=await i.handler(e)}catch(s){r=await this.#r.onError?.(e,s)??e.respond.text("Internal Server Error",500)}finally{await this.#r.onSend?.(e,r)}return r??e.respond.text("",204)}getRoutes(){return this.#s.map(e=>({method:e.method,path:e.path,params:e.params||[],compiled:!0}))}};te();ee();import $t from"node:http";var Y=class extends I{#s=new Set;constructor(){super("http")}async initialize(e,r={},s=null){await super.initialize(e,r,s),r.middleware?.length>0&&(s?.warn('Middleware configured but HTTP adapter selected. Consider using adapter: "express" for full middleware support.'),s?.info("HTTP adapter will simulate middleware using hooks for basic compatibility."))}async start({port:e=3e3,host:r="0.0.0.0"}={}){return this.server=$t.createServer(async(s,o)=>{try{if(this.opts.middleware?.length>0&&!await this.#t(s,o,this.opts.middleware))return;s.body||(s.body=await Ae(s));let i=this.createContext(s,o),a=await this.kernel.handle(i);await this.sendResponse(o,a,s.method==="HEAD")}catch(i){await this.handleError(o,i)}}),this.server.on("connection",s=>{this.#s.add(s),s.on("close",()=>{this.#s.delete(s)})}),await new Promise((s,o)=>this.server.listen(e,r,i=>i?o(i):s())),this.log?.info?.(`HTTP Server listening on http://${r}:${e}`),this.server}async stop(){if(this.server){for(let e of this.#s)e.destroy();this.#s.clear(),await new Promise(e=>this.server.close(()=>e())),this.server=null}}async#t(e,r,s){for(let o of s)try{let i=!1,a=n=>{if(n)throw n;i=!0};if(r.json||(r.json=n=>(r.setHeader("Content-Type","application/json"),r.end(JSON.stringify(n)),!1)),await o(e,r,a),!i&&r.headersSent)return!1}catch(i){return this.log?.error(`Middleware simulation error: ${i.message}`),r.statusCode=500,r.end("Internal Server Error"),!1}return!0}};var yr=10,st=(t=0)=>e=>`\x1B[${e+t}m`,nt=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,ot=(t=0)=>(e,r,s)=>`\x1B[${38+t};2;${e};${r};${s}m`,f={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},it=Object.keys(f.modifier),ye=Object.keys(f.color),be=Object.keys(f.bgColor),at=[...ye,...be];function kt(){let t=new Map;for(let[e,r]of Object.entries(f)){for(let[s,o]of Object.entries(r))f[s]={open:`\x1B[${o[0]}m`,close:`\x1B[${o[1]}m`},r[s]=f[s],t.set(o[0],o[1]);Object.defineProperty(f,e,{value:r,enumerable:!1})}return Object.defineProperty(f,"codes",{value:t,enumerable:!1}),f.color.close="\x1B[39m",f.bgColor.close="\x1B[49m",f.color.ansi=st(),f.color.ansi256=nt(),f.color.ansi16m=ot(),f.bgColor.ansi=st(10),f.bgColor.ansi256=nt(10),f.bgColor.ansi16m=ot(10),Object.defineProperties(f,{rgbToAnsi256:{value(e,r,s){return e===r&&r===s?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(r/255*5)+Math.round(s/255*5)},enumerable:!1},hexToRgb:{value(e){let r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!r)return[0,0,0];let[s]=r;s.length===3&&(s=[...s].map(i=>i+i).join(""));let o=Number.parseInt(s,16);return[o>>16&255,o>>8&255,o&255]},enumerable:!1},hexToAnsi256:{value:e=>f.rgbToAnsi256(...f.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let r,s,o;if(e>=232)r=((e-232)*10+8)/255,s=r,o=r;else{e-=16;let n=e%36;r=Math.floor(e/36)/5,s=Math.floor(n/6)/5,o=n%6/5}let i=Math.max(r,s,o)*2;if(i===0)return 30;let a=30+(Math.round(o)<<2|Math.round(s)<<1|Math.round(r));return i===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,r,s)=>f.ansi256ToAnsi(f.rgbToAnsi256(e,r,s)),enumerable:!1},hexToAnsi:{value:e=>f.ansi256ToAnsi(f.hexToAnsi256(e)),enumerable:!1}}),f}var Ot=kt(),C=Ot;import we from"node:process";import Pt from"node:os";import lt from"node:tty";function R(t,e=globalThis.Deno?globalThis.Deno.args:we.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",s=e.indexOf(r+t),o=e.indexOf("--");return s!==-1&&(o===-1||s<o)}var{env:d}=we,q;R("no-color")||R("no-colors")||R("color=false")||R("color=never")?q=0:(R("color")||R("colors")||R("color=true")||R("color=always"))&&(q=1);function jt(){if("FORCE_COLOR"in d)return d.FORCE_COLOR==="true"?1:d.FORCE_COLOR==="false"?0:d.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(d.FORCE_COLOR,10),3)}function It(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function Nt(t,{streamIsTTY:e,sniffFlags:r=!0}={}){let s=jt();s!==void 0&&(q=s);let o=r?q:s;if(o===0)return 0;if(r){if(R("color=16m")||R("color=full")||R("color=truecolor"))return 3;if(R("color=256"))return 2}if("TF_BUILD"in d&&"AGENT_NAME"in d)return 1;if(t&&!e&&o===void 0)return 0;let i=o||0;if(d.TERM==="dumb")return i;if(we.platform==="win32"){let a=Pt.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in d)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(a=>a in d)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(a=>a in d)||d.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in d)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(d.TEAMCITY_VERSION)?1:0;if(d.COLORTERM==="truecolor"||d.TERM==="xterm-kitty"||d.TERM==="xterm-ghostty"||d.TERM==="wezterm")return 3;if("TERM_PROGRAM"in d){let a=Number.parseInt((d.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(d.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(d.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(d.TERM)||"COLORTERM"in d?1:i}function ht(t,e={}){let r=Nt(t,{streamIsTTY:t&&t.isTTY,...e});return It(r)}var Lt={stdout:ht({isTTY:lt.isatty(1)}),stderr:ht({isTTY:lt.isatty(2)})},ct=Lt;function ut(t,e,r){let s=t.indexOf(e);if(s===-1)return t;let o=e.length,i=0,a="";do a+=t.slice(i,s)+e+r,i=s+o,s=t.indexOf(e,i);while(s!==-1);return a+=t.slice(i),a}function pt(t,e,r,s){let o=0,i="";do{let a=t[s-1]==="\r";i+=t.slice(o,a?s-1:s)+e+(a?`\r
2
2
  `:`
3
- `)+r,s=n+1,n=t.indexOf(`
4
- `,s)}while(n!==-1);return o+=t.slice(s),o}var{stdout:Et,stderr:At}=bt,ke=Symbol("GENERATOR"),F=Symbol("STYLER"),z=Symbol("IS_EMPTY"),Ct=["ansi","ansi","ansi256","ansi16m"],L=Object.create(null),rr=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let r=Et?Et.level:0;t.level=e.level===void 0?r:e.level};var nr=t=>{let e=(...r)=>r.join(" ");return rr(e,t),Object.setPrototypeOf(e,G.prototype),e};function G(t){return nr(t)}Object.setPrototypeOf(G.prototype,Function.prototype);for(let[t,e]of Object.entries(R))L[t]={get(){let r=Q(this,je(e.open,e.close,this[F]),this[z]);return Object.defineProperty(this,t,{value:r}),r}};L.visible={get(){let t=Q(this,this[F],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var Ie=(t,e,r,...n)=>t==="rgb"?e==="ansi16m"?R[r].ansi16m(...n):e==="ansi256"?R[r].ansi256(R.rgbToAnsi256(...n)):R[r].ansi(R.rgbToAnsi(...n)):t==="hex"?Ie("rgb",e,r,...R.hexToRgb(...n)):R[r][t](...n),sr=["rgb","hex","ansi256"];for(let t of sr){L[t]={get(){let{level:r}=this;return function(...n){let s=je(Ie(t,Ct[r],"color",...n),R.color.close,this[F]);return Q(this,s,this[z])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);L[e]={get(){let{level:r}=this;return function(...n){let s=je(Ie(t,Ct[r],"bgColor",...n),R.bgColor.close,this[F]);return Q(this,s,this[z])}}}}var ir=Object.defineProperties(()=>{},{...L,level:{enumerable:!0,get(){return this[ke].level},set(t){this[ke].level=t}}}),je=(t,e,r)=>{let n,s;return r===void 0?(n=t,s=e):(n=r.openAll+t,s=e+r.closeAll),{open:t,close:e,openAll:n,closeAll:s,parent:r}},Q=(t,e,r)=>{let n=(...s)=>or(n,s.length===1?""+s[0]:s.join(" "));return Object.setPrototypeOf(n,ir),n[ke]=t,n[F]=e,n[z]=r,n},or=(t,e)=>{if(t.level<=0||!e)return t[z]?"":e;let r=t[F];if(r===void 0)return e;let{openAll:n,closeAll:s}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=wt(e,r.close,r.open),r=r.parent;let o=e.indexOf(`
5
- `);return o!==-1&&(e=xt(e,s,n,o)),n+e+s};Object.defineProperties(G.prototype,L);var ar=G(),ss=G({level:At?At.level:0});var f=ar;import{exec as lr}from"child_process";import{promisify as cr}from"util";var hr=cr(lr);async function Rt({port:t,host:e,mode:r},n){let o=`${r==="production"?"https":"http"}://${e==="0.0.0.0"?"localhost":e}:${t}`;if(["",f.bold.blue("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),f.bold.blue("\u2551")+f.bold.white(" \u{1F680} Clovie Server Ready! \u{1F680} ")+f.bold.blue("\u2551"),f.bold.blue("\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),f.bold.blue("\u2551")+f.white(` Mode: ${f.green(r.toUpperCase())} `)+f.bold.blue("\u2551"),f.bold.blue("\u2551")+f.white(` URL: ${f.cyan.underline(o)} `)+f.bold.blue("\u2551"),f.bold.blue("\u2551")+f.white(` Host: ${f.yellow(e)}:${f.yellow(t)} `)+f.bold.blue("\u2551"),f.bold.blue("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),""].forEach(l=>n.info(l)),r==="development")try{await ur(o),n.info(f.green("\u{1F310} Browser opened automatically"))}catch(l){n.debug("Could not open browser automatically:",l.message)}["",f.gray("\u{1F4A1} Quick Commands:"),f.gray(` \u2022 Press ${f.yellow("Ctrl+C")} to stop the server`),f.gray(` \u2022 Visit ${f.cyan(o)} to view your site`),f.gray(" \u2022 Check the console for live reload updates"),""].forEach(l=>n.info(l))}async function ur(t){let e=process.platform,r;switch(e){case"darwin":r=`open "${t}"`;break;case"win32":r=`start "${t}"`;break;default:r=`xdg-open "${t}"`;break}try{await hr(r)}catch(n){throw new Error(`Failed to open browser: ${n.message}`)}}var Me=class extends H{static manifest={name:"Clovie Server",namespace:"server",version:"1.0.0"};#n=[];#t=null;#r={onRequest:null,preHandler:null,onSend:null,onError:null};#e=!1;#s={};#a=[];actions(e){return{use:(...r)=>(this.#a.push(...r),this),add:(r,n,s,o={})=>{this.#o(null,r,n,s,o)},useAdapter:r=>(this.#t=r,this),hooks:r=>(this.#r={...this.#r,...r},this),listen:async(r={})=>{this.#s={...this.config,...r},this.#e=!0,this.#f();let n=e("relay"),s=this.#s.port||3e3,o=this.#s.host||"0.0.0.0",a=e("log"),i=new J;if(i.hooks(this.#r),i.registerRoutes(this.#n),i.registerRoutes([{method:"GET",path:"/health",handler:u=>u.respond.json({status:"ok",timestamp:new Date().toISOString(),mode:this.#s.mode||"production"})},{method:"GET",path:"/api/info",handler:u=>u.respond.json({name:"Clovie",version:"1.0.0",mode:this.#s.mode||"production",routes:this.#n.length})}]),this.#s.outputDir&&i.setStaticFallback(this.#s.outputDir,(u,y)=>this.#p(u,y)),!this.#t)if(this.#s.adapter==="express"||this.#s.middleware?.length>0){let{ExpressAdapter:u}=await Promise.resolve().then(()=>(Tt(),vt));this.#t=u.create(),a.debug("Using Express adapter for middleware support")}else this.#t=Z.create(),a.debug("Using HTTP adapter");await this.#t.initialize(i,this.#s,a),typeof this.#t.registerKernelHandler=="function"&&this.#t.registerKernelHandler(this.#s);let l=await this.#t.start({port:s,host:o}),c=l.address()?.port||s;return await Rt({port:c,host:o,mode:this.#s.mode||"production"},a),n.broadcast("server:ready",l),l},getRoutes:()=>this.#n,clearRoutes:()=>{this.#n=[]},stop:async()=>{this.#t&&await this.#t.stop()},isRunning:()=>this.#t&&this.#t.isRunning(),getHttpServer:()=>this.#t?this.#t.getHttpServer():null}}#o(e="",r,n,s,o={},a=[]){if(e&&(n=e+n),Array.isArray(a))for(let i of a)typeof i=="function"?this.#e?this.#h(i):this.#a.push(i):this.#o(n,i.method,i.path,i.handler,i.meta,i.children);else typeof a=="function"&&(this.#e?this.#h(a):this.#a.push(a));this.#n.push({method:r.toUpperCase(),path:n,handler:s,meta:o})}#f(){this.#e&&this.#a.length!==0&&(this.#h(...this.#a),this.#a=[])}#h(...e){try{for(let r of e){let n=B(r);switch(n){case"routes":let s=r(this.useContext,this.#s);if(Array.isArray(s))for(let l of s)this.#o(null,l.method,l.path,l.handler,l.meta,l.children);else throw new Error("Routes must be an array");break;case"route":let o=r(this.useContext,this.#s);if(typeof o=="object"&&o!==null)this.#o(null,o.method,o.path,o.handler,o.meta,o.children);else throw new Error("Route must be an object");break;case"hooks":let a=r(this.useContext,this.#s);if(typeof a=="object"&&a!==null)this.#r={...this.#r,...a};else throw new Error("Hooks must be an object");break;case"hook":let i=r(this.useContext,this.#s);if(typeof i=="function")this.#r={...this.#r,...i};else throw new Error("Hook must be a function");break;default:throw new Error(`Invalid factory type: ${n}`)}}}catch(r){throw console.error(`
3
+ `)+r,o=s+1,s=t.indexOf(`
4
+ `,o)}while(s!==-1);return i+=t.slice(o),i}var{stdout:xe,stderr:ve}=ct,Re=Symbol("GENERATOR"),M=Symbol("STYLER"),_=Symbol("IS_EMPTY"),ft=["ansi","ansi","ansi256","ansi16m"],H=Object.create(null),Ft=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let r=xe?xe.level:0;t.level=e.level===void 0?r:e.level},dt=class{constructor(e){return mt(e)}},mt=t=>{let e=(...r)=>r.join(" ");return Ft(e,t),Object.setPrototypeOf(e,D.prototype),e};function D(t){return mt(t)}Object.setPrototypeOf(D.prototype,Function.prototype);for(let[t,e]of Object.entries(C))H[t]={get(){let r=X(this,Ce(e.open,e.close,this[M]),this[_]);return Object.defineProperty(this,t,{value:r}),r}};H.visible={get(){let t=X(this,this[M],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var Ee=(t,e,r,...s)=>t==="rgb"?e==="ansi16m"?C[r].ansi16m(...s):e==="ansi256"?C[r].ansi256(C.rgbToAnsi256(...s)):C[r].ansi(C.rgbToAnsi(...s)):t==="hex"?Ee("rgb",e,r,...C.hexToRgb(...s)):C[r][t](...s),Mt=["rgb","hex","ansi256"];for(let t of Mt){H[t]={get(){let{level:r}=this;return function(...s){let o=Ce(Ee(t,ft[r],"color",...s),C.color.close,this[M]);return X(this,o,this[_])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);H[e]={get(){let{level:r}=this;return function(...s){let o=Ce(Ee(t,ft[r],"bgColor",...s),C.bgColor.close,this[M]);return X(this,o,this[_])}}}}var Ht=Object.defineProperties(()=>{},{...H,level:{enumerable:!0,get(){return this[Re].level},set(t){this[Re].level=t}}}),Ce=(t,e,r)=>{let s,o;return r===void 0?(s=t,o=e):(s=r.openAll+t,o=e+r.closeAll),{open:t,close:e,openAll:s,closeAll:o,parent:r}},X=(t,e,r)=>{let s=(...o)=>Ut(s,o.length===1?""+o[0]:o.join(" "));return Object.setPrototypeOf(s,Ht),s[Re]=t,s[M]=e,s[_]=r,s},Ut=(t,e)=>{if(t.level<=0||!e)return t[_]?"":e;let r=t[M];if(r===void 0)return e;let{openAll:s,closeAll:o}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=ut(e,r.close,r.open),r=r.parent;let i=e.indexOf(`
5
+ `);return i!==-1&&(e=pt(e,o,s,i)),s+e+o};Object.defineProperties(D.prototype,H);var Bt=D(),Ar=D({level:ve?ve.level:0}),p=Bt;import{exec as _t}from"child_process";import{promisify as Dt}from"util";var Gt=Dt(_t);async function gt({port:t,host:e,mode:r},s){let i=`${r==="production"?"https":"http"}://${e==="0.0.0.0"?"localhost":e}:${t}`;if(["",p.bold.blue("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),p.bold.blue("\u2551")+p.bold.white(" \u{1F680} Clovie Server Ready! \u{1F680} ")+p.bold.blue("\u2551"),p.bold.blue("\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),p.bold.blue("\u2551")+p.white(` Mode: ${p.green(r.toUpperCase())} `)+p.bold.blue("\u2551"),p.bold.blue("\u2551")+p.white(` URL: ${p.cyan.underline(i)} `)+p.bold.blue("\u2551"),p.bold.blue("\u2551")+p.white(` Host: ${p.yellow(e)}:${p.yellow(t)} `)+p.bold.blue("\u2551"),p.bold.blue("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),""].forEach(l=>s.info(l)),r==="development")try{await zt(i),s.info(p.green("\u{1F310} Browser opened automatically"))}catch(l){s.debug("Could not open browser automatically:",l.message)}["",p.gray("\u{1F4A1} Quick Commands:"),p.gray(` \u2022 Press ${p.yellow("Ctrl+C")} to stop the server`),p.gray(` \u2022 Visit ${p.cyan(i)} to view your site`),p.gray(" \u2022 Check the console for live reload updates"),""].forEach(l=>s.info(l))}async function zt(t){let e=process.platform,r;switch(e){case"darwin":r=`open "${t}"`;break;case"win32":r=`start "${t}"`;break;default:r=`xdg-open "${t}"`;break}try{await Gt(r)}catch(s){throw new Error(`Failed to open browser: ${s.message}`)}}import{ServiceProvider as Vt,definitionType as Kt}from"@jucie.io/engine";var Te=class extends Vt{static manifest={name:"Clovie Server",namespace:"server",version:"1.0.0"};#s=[];#t=null;#r={onRequest:null,preHandler:null,onSend:null,onError:null};#e=!1;#n={};#a=[];actions(e){return{use:(...r)=>(this.#a.push(...r),this),add:(r,s,o,i={})=>{this.#i(null,r,s,o,i)},useAdapter:r=>(this.#t=r,this),hooks:r=>(this.#r={...this.#r,...r},this),listen:async(r={})=>{this.#n={...this.config,...r},this.#e=!0,this.#p();let s=e("relay"),o=this.#n.port||3e3,i=this.#n.host||"0.0.0.0",a=e("log"),n=new W;if(n.hooks(this.#r),n.registerRoutes(this.#s),n.registerRoutes([{method:"GET",path:"/health",handler:u=>u.respond.json({status:"ok",timestamp:new Date().toISOString(),mode:this.#n.mode||"production"})},{method:"GET",path:"/api/info",handler:u=>u.respond.json({name:"Clovie",version:"1.0.0",mode:this.#n.mode||"production",routes:this.#s.length})}]),this.#n.outputDir&&n.setStaticFallback(this.#n.outputDir,(u,m)=>this.#f(u,m)),!this.#t)if(this.#n.adapter==="express"||this.#n.middleware?.length>0){let{ExpressAdapter:u}=await Promise.resolve().then(()=>(Ie(),je));this.#t=u.create(),a.debug("Using Express adapter for middleware support")}else this.#t=Y.create(),a.debug("Using HTTP adapter");await this.#t.initialize(n,this.#n,a),typeof this.#t.registerKernelHandler=="function"&&this.#t.registerKernelHandler(this.#n);let l=await this.#t.start({port:o,host:i}),h=l.address()?.port||o;return await gt({port:h,host:i,mode:this.#n.mode||"production"},a),s.broadcast("server:ready",l),l},getRoutes:()=>this.#s,clearRoutes:()=>{this.#s=[]},stop:async()=>{this.#t&&await this.#t.stop()},isRunning:()=>this.#t&&this.#t.isRunning(),getHttpServer:()=>this.#t?this.#t.getHttpServer():null}}#i(e="",r,s,o,i={},a=[]){if(e&&(s=e+s),Array.isArray(a))for(let n of a)typeof n=="function"?this.#e?this.#c(n):this.#a.push(n):this.#i(s,n.method,n.path,n.handler,n.meta,n.children);else typeof a=="function"&&(this.#e?this.#c(a):this.#a.push(a));this.#s.push({method:r.toUpperCase(),path:s,handler:o,meta:i})}#p(){this.#e&&this.#a.length!==0&&(this.#c(...this.#a),this.#a=[])}#c(...e){try{for(let r of e){let s=Kt(r);switch(s){case"routes":let o=r(this.useContext,this.#n);if(Array.isArray(o))for(let l of o)this.#i(null,l.method,l.path,l.handler,l.meta,l.children);else throw new Error("Routes must be an array");break;case"route":let i=r(this.useContext,this.#n);if(typeof i=="object"&&i!==null)this.#i(null,i.method,i.path,i.handler,i.meta,i.children);else throw new Error("Route must be an object");break;case"hooks":let a=r(this.useContext,this.#n);if(typeof a=="object"&&a!==null)this.#r={...this.#r,...a};else throw new Error("Hooks must be an object");break;case"hook":let n=r(this.useContext,this.#n);if(typeof n=="function")this.#r={...this.#r,...n};else throw new Error("Hook must be a function");break;default:throw new Error(`Invalid factory type: ${s}`)}}}catch(r){throw console.error(`
6
6
  \u274C Error using factories: ${r.message}
7
- `),r}}async#p(e,r){let n=await import("fs/promises"),s=await import("path");try{let o=e.req.path==="/"?"/index.html":e.req.path,a=s.join(r,o),i;try{i=await n.stat(a)}catch{if(s.extname(o))return e.respond.text("Not Found",404);{let u=s.join(r,`${o}.html`);try{i=await n.stat(u),a=u}catch{return e.respond.text("Not Found",404)}}}if(i.isFile()){let l=s.extname(a),c=this.#i(l),u=await n.readFile(a);return c==="text/html"?e.respond.html(u.toString(),200):c==="text/css"?e.respond.text(u.toString(),200,{"Content-Type":"text/css"}):c==="application/javascript"?e.respond.text(u.toString(),200,{"Content-Type":"application/javascript"}):c.startsWith("text/")?e.respond.text(u.toString(),200,{"Content-Type":c}):e.respond.file(a,200,{"Content-Type":c})}else return e.respond.text("Not Found",404)}catch{return e.respond.text("Not Found",404)}}#i(e){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",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".eot":"application/vnd.ms-fontobject"}[e.toLowerCase()]||"application/octet-stream"}};var fr=w("routes",[Array]),pr=w("route",[Object]);var dr=w("hooks",[Object]),mr=w("hook",[Function]);export{Me as Server,mr as defineHook,dr as defineHooks,pr as defineRoute,fr as defineRoutes};
7
+ `),r}}async#f(e,r){let s=await import("fs/promises"),o=await import("path");try{let i=e.req.path==="/"?"/index.html":e.req.path,a=o.join(r,i),n;try{n=await s.stat(a)}catch{if(o.extname(i))return e.respond.text("Not Found",404);{let u=o.join(r,`${i}.html`);try{n=await s.stat(u),a=u}catch{return e.respond.text("Not Found",404)}}}if(n.isFile()){let l=o.extname(a),h=this.#o(l),u=await s.readFile(a);return h==="text/html"?e.respond.html(u.toString(),200):h==="text/css"?e.respond.text(u.toString(),200,{"Content-Type":"text/css"}):h==="application/javascript"?e.respond.text(u.toString(),200,{"Content-Type":"application/javascript"}):h.startsWith("text/")?e.respond.text(u.toString(),200,{"Content-Type":h}):e.respond.file(a,200,{"Content-Type":h})}else return e.respond.text("Not Found",404)}catch{return e.respond.text("Not Found",404)}}#o(e){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",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".eot":"application/vnd.ms-fontobject"}[e.toLowerCase()]||"application/octet-stream"}};import{createDefinition as yt}from"@jucie.io/engine";var Wt=yt("routes",[Array]),Yt=yt("route",[Object]);import{createDefinition as bt}from"@jucie.io/engine";var qt=bt("hooks",[Object]),Xt=bt("hook",[Function]);export{Te as Server,Xt as defineHook,qt as defineHooks,Yt as defineRoute,Wt as defineRoutes};
8
8
  //# sourceMappingURL=main.js.map