diesel-core 0.0.8 → 0.0.10

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/ctx.js CHANGED
@@ -1 +1 @@
1
- var w=(I,F)=>()=>(F||I((F={exports:{}}).exports,F),F.exports);var B=w((W)=>{function A(I,F){let E={},J={},X=!1,L=null,M=null,$=null,Y,R=200;return{req:I,url:F,next:()=>{},status(z){return R=z,this},body(){return K(this,void 0,void 0,function*(){if(!Y)Y=yield T(I);if(Y.error)return new Response(JSON.stringify({error:Y.error}),{status:400,headers:{"Content-Type":"application/json"}});return Y})},setHeader(z,G){return E[z]=G,this},set(z,G){return J[z]=G,this},get(z){return J[z]||null},setAuth(z){return X=z,this},getAuth(){return X},text(z,G){if(G)R=G;return new Response(z,{status:R,headers:E})},json(z,G){if(G)R=G;return new Response(JSON.stringify(z),{status:R,headers:Object.assign({"Content-Type":"application/json"},E)})},html(z,G){if(G)R=G;return new Response(Bun.file(z),{status:R,headers:Object.assign({},E)})},file(z,G){if(G)R=G;return new Response(Bun.file(z),{status:R,headers:Object.assign({},E)})},redirect(z,G){if(G)R=G;return new Response(null,{status:R,headers:Object.assign({Location:z},E)})},getParams(z){if(!$)$=Q(I===null||I===void 0?void 0:I.routePattern,F===null||F===void 0?void 0:F.pathname);return z?$[z]||null:$},getQuery(z){if(!L)L=Object.fromEntries(F.searchParams);return z?L[z]||null:L},cookie(z,G){return K(this,arguments,void 0,function*(H,V,U={}){let Z=`${encodeURIComponent(H)}=${encodeURIComponent(V)}`;if(U.maxAge)Z+=`; Max-Age=${U.maxAge}`;if(U.expires)Z+=`; Expires=${U.expires.toUTCString()}`;if(U.path)Z+=`; Path=${U.path}`;if(U.domain)Z+=`; Domain=${U.domain}`;if(U.secure)Z+="; Secure";if(U.httpOnly)Z+="; HttpOnly";if(U.sameSite)Z+=`; SameSite=${U.sameSite}`;if(E["Set-Cookie"]){const O=Array.isArray(E["Set-Cookie"])?E["Set-Cookie"]:[E["Set-Cookie"]];O.push(Z),E["Set-Cookie"]=O}else E["Set-Cookie"]=Z;return this})},getCookie(z){return K(this,void 0,void 0,function*(){if(!M){const G=I.headers.get("cookie");if(G)M=yield D(G)}return z?M[z]||null:M})}}}function D(I){return K(this,void 0,void 0,function*(){const F={};if(!I)return F;return I.split(";").forEach((J)=>{var X;const[L,M]=(X=J===null||J===void 0?void 0:J.trim())===null||X===void 0?void 0:X.split("=");if(L&&M)F[L.trim()]=M.split(" ")[0].trim()}),F})}function Q(I,F){const E={},J=I.split("/"),[X]=F.split("?"),L=X.split("/");if(J.length!==L.length)return null;return J.forEach((M,$)=>{if(M.startsWith(":")){const Y=M.slice(1);E[Y]=L[$]}}),E}function T(I){return K(this,void 0,void 0,function*(){const F=I.headers.get("Content-Type")||"";if(!F)return{};try{if(F.startsWith("application/json"))return yield I.json();if(F.startsWith("application/x-www-form-urlencoded")){const E=yield I.text();return Object.fromEntries(new URLSearchParams(E))}if(F.startsWith("multipart/form-data")){const E=yield I.formData();return b(E)}return{error:"Unknown request body type"}}catch(E){return{error:"Invalid request body format"}}})}function b(I){const F={};for(let[E,J]of I.entries())F[E]=J;return F}var K=W&&W.__awaiter||function(I,F,E,J){function X(L){return L instanceof E?L:new E(function(M){M(L)})}return new(E||(E=Promise))(function(L,M){function $(z){try{R(J.next(z))}catch(G){M(G)}}function Y(z){try{R(J.throw(z))}catch(G){M(G)}}function R(z){z.done?L(z.value):X(z.value).then($,Y)}R((J=J.apply(I,F||[])).next())})};Object.defineProperty(W,"__esModule",{value:!0});W.default=A});export default B();
1
+ async function E(I){const G={};if(!I)return G;return I.split(";").forEach((M)=>{const[U,L]=M?.trim()?.split("=");if(U&&L)G[U.trim()]=L.split(" ")[0].trim()}),G}function K(I,G){const z={},M=I.split("/"),[U]=G.split("?"),L=U.split("/");if(M.length!==L.length)return null;return M.forEach((X,Z)=>{if(X.startsWith(":")){const Y=X.slice(1);z[Y]=L[Z]}}),z}async function W(I){const G=I.headers.get("Content-Type")||"";if(!G)return{};try{if(G.startsWith("application/json"))return await I.json();if(G.startsWith("application/x-www-form-urlencoded")){const z=await I.text();return Object.fromEntries(new URLSearchParams(z))}if(G.startsWith("multipart/form-data")){const z=await I.formData();return A(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}}function A(I){const G={};for(let[z,M]of I.entries())G[z]=M;return G}function $(I,G){let z=new Headers,M={},U=!1,L=null,X=null,Z=null,Y,_=200;return{req:I,url:G,next:()=>{},status(w){return _=w,this},async body(){if(!Y)Y=await W(I);if(Y.error)return new Response(JSON.stringify({error:Y.error}),{status:400});return Y},setHeader(w,F){return z.set(w,F),this},set(w,F){return M[w]=F,this},get(w){return M[w]||null},setAuth(w){return U=w,this},getAuth(){return U},text(w,F){return new Response(w,{status:F??_,headers:z})},json(w,F){return new Response(JSON.stringify(w),{status:F??_,headers:z})},html(w,F){return new Response(Bun.file(w),{status:F??_,headers:z})},file(w,F){return new Response(Bun.file(w),{status:F??_,headers:z})},redirect(w,F){return z.set("Location",w),new Response(null,{status:F??302,headers:z})},getParams(w){if(!Z)Z=K(I?.routePattern,G?.pathname);return w?Z[w]||null:Z},getQuery(w){if(!L)L=Object.fromEntries(G.searchParams);return w?L[w]||null:L},async cookie(w,F,J={}){let R=`${encodeURIComponent(w)}=${encodeURIComponent(F)}`;if(J.maxAge)R+=`; Max-Age=${J.maxAge}`;if(J.expires)R+=`; Expires=${J.expires.toUTCString()}`;if(J.path)R+=`; Path=${J.path}`;if(J.domain)R+=`; Domain=${J.domain}`;if(J.secure)R+="; Secure";if(J.httpOnly)R+="; HttpOnly";if(J.sameSite)R+=`; SameSite=${J.sameSite}`;return z?.append("Set-Cookie",R),this},async getCookie(w){if(!X){const F=I.headers.get("cookie");if(F)X=await E(F)}return w?X[w]||null:X}}}export{$ as default};
@@ -1 +1 @@
1
- var B=(F,G)=>()=>(G||F((G={exports:{}}).exports,G),G.exports);var D=B((V)=>{function A(F,G){let z={},J={},X=!1,I=null,U=null,K=null,$,Y=200;return{req:F,url:G,next:()=>{},status(E){return Y=E,this},body(){return O(this,void 0,void 0,function*(){if(!$)$=yield H(F);if($.error)return new Response(JSON.stringify({error:$.error}),{status:400,headers:{"Content-Type":"application/json"}});return $})},setHeader(E,L){return z[E]=L,this},set(E,L){return J[E]=L,this},get(E){return J[E]||null},setAuth(E){return X=E,this},getAuth(){return X},text(E,L){if(L)Y=L;return new Response(E,{status:Y,headers:z})},json(E,L){if(L)Y=L;return new Response(JSON.stringify(E),{status:Y,headers:Object.assign({"Content-Type":"application/json"},z)})},html(E,L){if(L)Y=L;return new Response(Bun.file(E),{status:Y,headers:Object.assign({},z)})},file(E,L){if(L)Y=L;return new Response(Bun.file(E),{status:Y,headers:Object.assign({},z)})},redirect(E,L){if(L)Y=L;return new Response(null,{status:Y,headers:Object.assign({Location:E},z)})},getParams(E){if(!K)K=f(F===null||F===void 0?void 0:F.routePattern,G===null||G===void 0?void 0:G.pathname);return E?K[E]||null:K},getQuery(E){if(!I)I=Object.fromEntries(G.searchParams);return E?I[E]||null:I},cookie(E,L){return O(this,arguments,void 0,function*(R,b,Z={}){let M=`${encodeURIComponent(R)}=${encodeURIComponent(b)}`;if(Z.maxAge)M+=`; Max-Age=${Z.maxAge}`;if(Z.expires)M+=`; Expires=${Z.expires.toUTCString()}`;if(Z.path)M+=`; Path=${Z.path}`;if(Z.domain)M+=`; Domain=${Z.domain}`;if(Z.secure)M+="; Secure";if(Z.httpOnly)M+="; HttpOnly";if(Z.sameSite)M+=`; SameSite=${Z.sameSite}`;if(z["Set-Cookie"]){const T=Array.isArray(z["Set-Cookie"])?z["Set-Cookie"]:[z["Set-Cookie"]];T.push(M),z["Set-Cookie"]=T}else z["Set-Cookie"]=M;return this})},getCookie(E){return O(this,void 0,void 0,function*(){if(!U){const L=F.headers.get("cookie");if(L)U=yield C(L)}return E?U[E]||null:U})}}}function C(F){return O(this,void 0,void 0,function*(){const G={};if(!F)return G;return F.split(";").forEach((J)=>{var X;const[I,U]=(X=J===null||J===void 0?void 0:J.trim())===null||X===void 0?void 0:X.split("=");if(I&&U)G[I.trim()]=U.split(" ")[0].trim()}),G})}function f(F,G){const z={},J=F.split("/"),[X]=G.split("?"),I=X.split("/");if(J.length!==I.length)return null;return J.forEach((U,K)=>{if(U.startsWith(":")){const $=U.slice(1);z[$]=I[K]}}),z}function H(F){return O(this,void 0,void 0,function*(){const G=F.headers.get("Content-Type")||"";if(!G)return{};try{if(G.startsWith("application/json"))return yield F.json();if(G.startsWith("application/x-www-form-urlencoded")){const z=yield F.text();return Object.fromEntries(new URLSearchParams(z))}if(G.startsWith("multipart/form-data")){const z=yield F.formData();return j(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}})}function j(F){const G={};for(let[z,J]of F.entries())G[z]=J;return G}var O=V&&V.__awaiter||function(F,G,z,J){function X(I){return I instanceof z?I:new z(function(U){U(I)})}return new(z||(z=Promise))(function(I,U){function K(E){try{Y(J.next(E))}catch(L){U(L)}}function $(E){try{Y(J.throw(E))}catch(L){U(L)}}function Y(E){E.done?I(E.value):X(E.value).then(K,$)}Y((J=J.apply(F,G||[])).next())})};Object.defineProperty(V,"__esModule",{value:!0});V.default=A});var S=B((W)=>{function P(F,G,z){return N(this,void 0,void 0,function*(){const J=_.default(F,G);if(z.hasOnReqHook)yield z.hooks.onRequest(J);if(z.hasMiddleware){const I=[...z.globalMiddlewares,...z.middlewares.get(G.pathname)||[]],U=yield y(I,J);if(U)return U}let X;if(Q[G.pathname+F.method])X=Q[G.pathname+F.method];else X=z.trie.search(G.pathname,F.method),Q[G.pathname+F.method]=X;if(!X||!X.handler)return new Response(`Route not found for ${G.pathname}`,{status:404});if(X.method!==F.method)return new Response("Method not allowed",{status:405});if(X.isDynamic)F.routePattern=X.path;if(z.hasPreHandlerHook){const I=yield z.hooks.preHandler(J);if(I)return I}try{const I=yield X.handler(J);if(z.hasPostHandlerHook)yield z.hooks.postHandler(J);if(z.hasOnSendHook){const U=yield z.hooks.onSend(I,J);if(U)return U}return I!==null&&I!==void 0?I:new Response("No response from handler",{status:204})}catch(I){return new Response("Internal Server Error",{status:500})}})}function y(F,G){return N(this,void 0,void 0,function*(){for(let z of F){const J=yield z(G);if(J)return J}})}var N=W&&W.__awaiter||function(F,G,z,J){function X(I){return I instanceof z?I:new z(function(U){U(I)})}return new(z||(z=Promise))(function(I,U){function K(E){try{Y(J.next(E))}catch(L){U(L)}}function $(E){try{Y(J.throw(E))}catch(L){U(L)}}function Y(E){E.done?I(E.value):X(E.value).then(K,$)}Y((J=J.apply(F,G||[])).next())})},w=W&&W.__importDefault||function(F){return F&&F.__esModule?F:{default:F}};Object.defineProperty(W,"__esModule",{value:!0});W.default=P;var _=w(D()),Q={}});export default S();
1
+ async function A(I){const G={};if(!I)return G;return I.split(";").forEach((J)=>{const[X,L]=J?.trim()?.split("=");if(X&&L)G[X.trim()]=L.split(" ")[0].trim()}),G}function O(I,G){const z={},J=I.split("/"),[X]=G.split("?"),L=X.split("/");if(J.length!==L.length)return null;return J.forEach((Y,E)=>{if(Y.startsWith(":")){const $=Y.slice(1);z[$]=L[E]}}),z}async function V(I){const G=I.headers.get("Content-Type")||"";if(!G)return{};try{if(G.startsWith("application/json"))return await I.json();if(G.startsWith("application/x-www-form-urlencoded")){const z=await I.text();return Object.fromEntries(new URLSearchParams(z))}if(G.startsWith("multipart/form-data")){const z=await I.formData();return D(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}}function D(I){const G={};for(let[z,J]of I.entries())G[z]=J;return G}function M(I,G){let z=new Headers,J={},X=!1,L=null,Y=null,E=null,$,K=200;return{req:I,url:G,next:()=>{},status(F){return K=F,this},async body(){if(!$)$=await V(I);if($.error)return new Response(JSON.stringify({error:$.error}),{status:400});return $},setHeader(F,U){return z.set(F,U),this},set(F,U){return J[F]=U,this},get(F){return J[F]||null},setAuth(F){return X=F,this},getAuth(){return X},text(F,U){return new Response(F,{status:U??K,headers:z})},json(F,U){return new Response(JSON.stringify(F),{status:U??K,headers:z})},html(F,U){return new Response(Bun.file(F),{status:U??K,headers:z})},file(F,U){return new Response(Bun.file(F),{status:U??K,headers:z})},redirect(F,U){return z.set("Location",F),new Response(null,{status:U??302,headers:z})},getParams(F){if(!E)E=O(I?.routePattern,G?.pathname);return F?E[F]||null:E},getQuery(F){if(!L)L=Object.fromEntries(G.searchParams);return F?L[F]||null:L},async cookie(F,U,Z={}){let _=`${encodeURIComponent(F)}=${encodeURIComponent(U)}`;if(Z.maxAge)_+=`; Max-Age=${Z.maxAge}`;if(Z.expires)_+=`; Expires=${Z.expires.toUTCString()}`;if(Z.path)_+=`; Path=${Z.path}`;if(Z.domain)_+=`; Domain=${Z.domain}`;if(Z.secure)_+="; Secure";if(Z.httpOnly)_+="; HttpOnly";if(Z.sameSite)_+=`; SameSite=${Z.sameSite}`;return z?.append("Set-Cookie",_),this},async getCookie(F){if(!Y){const U=I.headers.get("cookie");if(U)Y=await A(U)}return F?Y[F]||null:Y}}}async function R(I,G){for(let z of I){const J=await z(G);if(J)return J}}var W={};async function Q(I,G,z){const J=M(I,G);if(z.hasOnReqHook)await z.hooks.onRequest(J);if(z.hasMiddleware){const L=[...z.globalMiddlewares,...z.middlewares.get(G.pathname)||[]],Y=await R(L,J);if(Y)return Y}let X;if(W[G.pathname+I.method])X=W[G.pathname+I.method];else X=z.trie.search(G.pathname,I.method),W[G.pathname+I.method]=X;if(!X||!X.handler)return new Response(`Route not found for ${G.pathname}`,{status:404});if(X.method!==I.method)return new Response("Method not allowed",{status:405});if(X.isDynamic)I.routePattern=X.path;if(z.hasPreHandlerHook){const L=await z.hooks.preHandler(J);if(L)return L}try{const L=await X.handler(J);if(z.hasPostHandlerHook)await z.hooks.postHandler(J);if(z.hasOnSendHook){const Y=await z.hooks.onSend(L,J);if(Y)return Y}return L??new Response("No response from handler",{status:204})}catch(L){return new Response("Internal Server Error",{status:500})}}export{Q as default};
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- var C=(J,L)=>()=>(L||J((L={exports:{}}).exports,L),L.exports);var S=C((D)=>{Object.defineProperty(D,"__esModule",{value:!0});class O{constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class j{constructor(){this.root=new O}insert(J,L){let z=this.root;const U=J.split("/").filter(Boolean);if(J==="/"){z.isEndOfWord=!0,z.handler.push(L.handler),z.path=J,z.method.push(L.method);return}for(let X of U){let Y=!1,Z=X;if(X.startsWith(":"))Y=!0,Z=":";if(!z.children[Z])z.children[Z]=new O;z=z.children[Z],z.isDynamic=Y,z.pattern=X}z.isEndOfWord=!0,z.method.push(L.method),z.handler.push(L.handler),z.path=J}search(J,L){let z=this.root;const U=J.split("/").filter(Boolean);for(let Y of U){let Z=Y;if(!z.children[Z])if(z.children[":"])z=z.children[":"];else return null;else z=z.children[Z]}let X=z.method.indexOf(L);if(X!==-1)return{path:z.path,handler:z.handler[X],isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[X]};return{path:z.path,handler:z.handler,isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[X]}}}D.default=j});var H=C((I)=>{function k(J,L){let z={},U={},X=!1,Y=null,Z=null,W=null,G,V=200;return{req:J,url:L,next:()=>{},status($){return V=$,this},body(){return T(this,void 0,void 0,function*(){if(!G)G=yield c(J);if(G.error)return new Response(JSON.stringify({error:G.error}),{status:400,headers:{"Content-Type":"application/json"}});return G})},setHeader($,E){return z[$]=E,this},set($,E){return U[$]=E,this},get($){return U[$]||null},setAuth($){return X=$,this},getAuth(){return X},text($,E){if(E)V=E;return new Response($,{status:V,headers:z})},json($,E){if(E)V=E;return new Response(JSON.stringify($),{status:V,headers:Object.assign({"Content-Type":"application/json"},z)})},html($,E){if(E)V=E;return new Response(Bun.file($),{status:V,headers:Object.assign({},z)})},file($,E){if(E)V=E;return new Response(Bun.file($),{status:V,headers:Object.assign({},z)})},redirect($,E){if(E)V=E;return new Response(null,{status:V,headers:Object.assign({Location:$},z)})},getParams($){if(!W)W=m(J===null||J===void 0?void 0:J.routePattern,L===null||L===void 0?void 0:L.pathname);return $?W[$]||null:W},getQuery($){if(!Y)Y=Object.fromEntries(L.searchParams);return $?Y[$]||null:Y},cookie($,E){return T(this,arguments,void 0,function*(f,v,Q={}){let F=`${encodeURIComponent(f)}=${encodeURIComponent(v)}`;if(Q.maxAge)F+=`; Max-Age=${Q.maxAge}`;if(Q.expires)F+=`; Expires=${Q.expires.toUTCString()}`;if(Q.path)F+=`; Path=${Q.path}`;if(Q.domain)F+=`; Domain=${Q.domain}`;if(Q.secure)F+="; Secure";if(Q.httpOnly)F+="; HttpOnly";if(Q.sameSite)F+=`; SameSite=${Q.sameSite}`;if(z["Set-Cookie"]){const R=Array.isArray(z["Set-Cookie"])?z["Set-Cookie"]:[z["Set-Cookie"]];R.push(F),z["Set-Cookie"]=R}else z["Set-Cookie"]=F;return this})},getCookie($){return T(this,void 0,void 0,function*(){if(!Z){const E=J.headers.get("cookie");if(E)Z=yield _(E)}return $?Z[$]||null:Z})}}}function _(J){return T(this,void 0,void 0,function*(){const L={};if(!J)return L;return J.split(";").forEach((U)=>{var X;const[Y,Z]=(X=U===null||U===void 0?void 0:U.trim())===null||X===void 0?void 0:X.split("=");if(Y&&Z)L[Y.trim()]=Z.split(" ")[0].trim()}),L})}function m(J,L){const z={},U=J.split("/"),[X]=L.split("?"),Y=X.split("/");if(U.length!==Y.length)return null;return U.forEach((Z,W)=>{if(Z.startsWith(":")){const G=Z.slice(1);z[G]=Y[W]}}),z}function c(J){return T(this,void 0,void 0,function*(){const L=J.headers.get("Content-Type")||"";if(!L)return{};try{if(L.startsWith("application/json"))return yield J.json();if(L.startsWith("application/x-www-form-urlencoded")){const z=yield J.text();return Object.fromEntries(new URLSearchParams(z))}if(L.startsWith("multipart/form-data")){const z=yield J.formData();return h(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}})}function h(J){const L={};for(let[z,U]of J.entries())L[z]=U;return L}var T=I&&I.__awaiter||function(J,L,z,U){function X(Y){return Y instanceof z?Y:new z(function(Z){Z(Y)})}return new(z||(z=Promise))(function(Y,Z){function W($){try{V(U.next($))}catch(E){Z(E)}}function G($){try{V(U.throw($))}catch(E){Z(E)}}function V($){$.done?Y($.value):X($.value).then(W,G)}V((U=U.apply(J,L||[])).next())})};Object.defineProperty(I,"__esModule",{value:!0});I.default=k});var q=C((B)=>{function i(J,L,z){return w(this,void 0,void 0,function*(){const U=p.default(J,L);if(z.hasOnReqHook)yield z.hooks.onRequest(U);if(z.hasMiddleware){const Y=[...z.globalMiddlewares,...z.middlewares.get(L.pathname)||[]],Z=yield n(Y,U);if(Z)return Z}let X;if(b[L.pathname+J.method])X=b[L.pathname+J.method];else X=z.trie.search(L.pathname,J.method),b[L.pathname+J.method]=X;if(!X||!X.handler)return new Response(`Route not found for ${L.pathname}`,{status:404});if(X.method!==J.method)return new Response("Method not allowed",{status:405});if(X.isDynamic)J.routePattern=X.path;if(z.hasPreHandlerHook){const Y=yield z.hooks.preHandler(U);if(Y)return Y}try{const Y=yield X.handler(U);if(z.hasPostHandlerHook)yield z.hooks.postHandler(U);if(z.hasOnSendHook){const Z=yield z.hooks.onSend(Y,U);if(Z)return Z}return Y!==null&&Y!==void 0?Y:new Response("No response from handler",{status:204})}catch(Y){return new Response("Internal Server Error",{status:500})}})}function n(J,L){return w(this,void 0,void 0,function*(){for(let z of J){const U=yield z(L);if(U)return U}})}var w=B&&B.__awaiter||function(J,L,z,U){function X(Y){return Y instanceof z?Y:new z(function(Z){Z(Y)})}return new(z||(z=Promise))(function(Y,Z){function W($){try{V(U.next($))}catch(E){Z(E)}}function G($){try{V(U.throw($))}catch(E){Z(E)}}function V($){$.done?Y($.value):X($.value).then(W,G)}V((U=U.apply(J,L||[])).next())})},u=B&&B.__importDefault||function(J){return J&&J.__esModule?J:{default:J}};Object.defineProperty(B,"__esModule",{value:!0});B.default=i;var p=u(H()),b={}});var o=C((M)=>{var l=M&&M.__awaiter||function(J,L,z,U){function X(Y){return Y instanceof z?Y:new z(function(Z){Z(Y)})}return new(z||(z=Promise))(function(Y,Z){function W($){try{V(U.next($))}catch(E){Z(E)}}function G($){try{V(U.throw($))}catch(E){Z(E)}}function V($){$.done?Y($.value):X($.value).then(W,G)}V((U=U.apply(J,L||[])).next())})},N=M&&M.__classPrivateFieldGet||function(J,L,z,U){if(z==="a"&&!U)throw new TypeError("Private accessor was defined without a getter");if(typeof L==="function"?J!==L||!U:!L.has(J))throw new TypeError("Cannot read private member from an object whose class did not declare it");return z==="m"?U:z==="a"?U.call(J):U?U.value:L.get(J)},P=M&&M.__importDefault||function(J){return J&&J.__esModule?J:{default:J}},K,A;Object.defineProperty(M,"__esModule",{value:!0});var y=P(S()),d=P(q());class x{constructor(){K.add(this),this.routes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new y.default,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hooks={onRequest:null,preHandler:null,postHandler:null,onSend:null,onError:null,onClose:null}}addHooks(J,L){if(typeof J!=="string")throw new Error("hookName must be a string");if(typeof L!=="function")throw new Error("callback must be a instance of function");if(this.hooks.hasOwnProperty(J))this.hooks[J]=L;else throw new Error(`Unknown hook type: ${J}`)}compile(){if(this.globalMiddlewares.length>0)this.hasMiddleware=!0;for(let[J,L]of this.middlewares.entries())if(L.length>0){this.hasMiddleware=!0;break}if(this.hooks.onRequest)this.hasOnReqHook=!0;if(this.hooks.preHandler)this.hasPreHandlerHook=!0;if(this.hooks.postHandler)this.hasPostHandlerHook=!0;if(this.hooks.onSend)this.hasOnSendHook=!0}listen(J,L,{sslCert:z=null,sslKey:U=null}={}){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");if(typeof J!=="number")throw new Error("Port must be a numeric value");this.compile();const X={port:J,fetch:(Z)=>l(this,void 0,void 0,function*(){const W=new URL(Z.url);try{return yield d.default(Z,W,this)}catch(G){return new Response("Internal Server Error",{status:500})}}),onClose(){console.log("Server is shutting down...")}};if(z&&U)X.certFile=z,X.keyFile=U;const Y=Bun.serve(X);if(typeof L==="function")return L();if(z&&U)console.log(`HTTPS server is running on https://localhost:${J}`);else console.log(`HTTP server is running on http://localhost:${J}`);return Y}register(J,L){if(typeof J!=="string")throw new Error("path must be a string");if(typeof L!=="object")throw new Error("handler parameter should be a instance of router object",L);const z=Object.entries(L.trie.root.children);L.trie.root.subMiddlewares.forEach((U,X)=>{if(!this.middlewares.has(J+X))this.middlewares.set(J+X,[]);U===null||U===void 0||U.forEach((Y)=>{var Z,W;if(!((Z=this.middlewares.get(J+X))===null||Z===void 0?void 0:Z.includes(Y)))(W=this.middlewares.get(J+X))===null||W===void 0||W.push(Y)})});for(let[U,X]of z){const Y=J+(X===null||X===void 0?void 0:X.path),Z=X.handler[0],W=X.method[0];this.trie.insert(Y,{handler:Z,method:W})}L.trie=new y.default}use(J,L){var z,U;if(typeof J==="function"){if(!this.globalMiddlewares.includes(J))return this.globalMiddlewares.push(J)}const X=J;if(!this.middlewares.has(X))this.middlewares.set(X,[]);if(!((z=this.middlewares.get(X))===null||z===void 0?void 0:z.includes(L)))(U=this.middlewares.get(X))===null||U===void 0||U.push(L)}get(J,...L){return N(this,K,"m",A).call(this,"GET",J,L),this}post(J,...L){return N(this,K,"m",A).call(this,"POST",J,L),this}put(J,...L){return N(this,K,"m",A).call(this,"PUT",J,L),this}patch(J,...L){return N(this,K,"m",A).call(this,"PATCH",J,L),this}delete(J,...L){return N(this,K,"m",A).call(this,"DELETE",J,L),this}}K=new WeakSet,A=function J(L,z,U){if(typeof z!=="string")throw new Error("Path must be a string type");if(typeof L!=="string")throw new Error("method must be a string type");const X=U.slice(0,-1),Y=U[U.length-1];if(!this.middlewares.has(z))this.middlewares.set(z,[]);X.forEach((Z)=>{var W,G;if(z==="/"){if(!this.globalMiddlewares.includes(Z))this.globalMiddlewares.push(Z)}else if(!((W=this.middlewares.get(z))===null||W===void 0?void 0:W.includes(Z)))(G=this.middlewares.get(z))===null||G===void 0||G.push(Z)}),this.trie.insert(z,{handler:Y,method:L})};M.default=x});export default o();
1
+ class Q{children;isEndOfWord;handler;isDynamic;pattern;path;method;subMiddlewares;constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class V{root;constructor(){this.root=new Q}insert(F,G){let z=this.root;const U=F.split("/").filter(Boolean);if(F==="/"){z.isEndOfWord=!0,z.handler.push(G.handler),z.path=F,z.method.push(G.method);return}for(let J of U){let L=!1,Y=J;if(J.startsWith(":"))L=!0,Y=":";if(!z.children[Y])z.children[Y]=new Q;z=z.children[Y],z.isDynamic=L,z.pattern=J}z.isEndOfWord=!0,z.method.push(G.method),z.handler.push(G.handler),z.path=F}search(F,G){let z=this.root;const U=F.split("/").filter(Boolean);for(let L of U){let Y=L;if(!z.children[Y])if(z.children[":"])z=z.children[":"];else return null;else z=z.children[Y]}let J=z.method.indexOf(G);if(J!==-1)return{path:z.path,handler:z.handler[J],isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[J]};return{path:z.path,handler:z.handler,isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[J]}}}async function D(F){const G={};if(!F)return G;return F.split(";").forEach((U)=>{const[J,L]=U?.trim()?.split("=");if(J&&L)G[J.trim()]=L.split(" ")[0].trim()}),G}function v(F,G){const z={},U=F.split("/"),[J]=G.split("?"),L=J.split("/");if(U.length!==L.length)return null;return U.forEach((Y,$)=>{if(Y.startsWith(":")){const W=Y.slice(1);z[W]=L[$]}}),z}async function T(F){const G=F.headers.get("Content-Type")||"";if(!G)return{};try{if(G.startsWith("application/json"))return await F.json();if(G.startsWith("application/x-www-form-urlencoded")){const z=await F.text();return Object.fromEntries(new URLSearchParams(z))}if(G.startsWith("multipart/form-data")){const z=await F.formData();return b(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}}function b(F){const G={};for(let[z,U]of F.entries())G[z]=U;return G}function M(F,G){let z=new Headers,U={},J=!1,L=null,Y=null,$=null,W,E=200;return{req:F,url:G,next:()=>{},status(X){return E=X,this},async body(){if(!W)W=await T(F);if(W.error)return new Response(JSON.stringify({error:W.error}),{status:400});return W},setHeader(X,Z){return z.set(X,Z),this},set(X,Z){return U[X]=Z,this},get(X){return U[X]||null},setAuth(X){return J=X,this},getAuth(){return J},text(X,Z){return new Response(X,{status:Z??E,headers:z})},json(X,Z){return new Response(JSON.stringify(X),{status:Z??E,headers:z})},html(X,Z){return new Response(Bun.file(X),{status:Z??E,headers:z})},file(X,Z){return new Response(Bun.file(X),{status:Z??E,headers:z})},redirect(X,Z){return z.set("Location",X),new Response(null,{status:Z??302,headers:z})},getParams(X){if(!$)$=v(F?.routePattern,G?.pathname);return X?$[X]||null:$},getQuery(X){if(!L)L=Object.fromEntries(G.searchParams);return X?L[X]||null:L},async cookie(X,Z,_={}){let A=`${encodeURIComponent(X)}=${encodeURIComponent(Z)}`;if(_.maxAge)A+=`; Max-Age=${_.maxAge}`;if(_.expires)A+=`; Expires=${_.expires.toUTCString()}`;if(_.path)A+=`; Path=${_.path}`;if(_.domain)A+=`; Domain=${_.domain}`;if(_.secure)A+="; Secure";if(_.httpOnly)A+="; HttpOnly";if(_.sameSite)A+=`; SameSite=${_.sameSite}`;return z?.append("Set-Cookie",A),this},async getCookie(X){if(!Y){const Z=F.headers.get("cookie");if(Z)Y=await D(Z)}return X?Y[X]||null:Y}}}async function N(F,G){for(let z of F){const U=await z(G);if(U)return U}}var B={};async function K(F,G,z){const U=M(F,G);if(z.hasOnReqHook)await z.hooks.onRequest(U);if(z.hasMiddleware){const L=[...z.globalMiddlewares,...z.middlewares.get(G.pathname)||[]],Y=await N(L,U);if(Y)return Y}let J;if(B[G.pathname+F.method])J=B[G.pathname+F.method];else J=z.trie.search(G.pathname,F.method),B[G.pathname+F.method]=J;if(!J||!J.handler)return new Response(`Route not found for ${G.pathname}`,{status:404});if(J.method!==F.method)return new Response("Method not allowed",{status:405});if(J.isDynamic)F.routePattern=J.path;if(z.hasPreHandlerHook){const L=await z.hooks.preHandler(U);if(L)return L}try{const L=await J.handler(U);if(z.hasPostHandlerHook)await z.hooks.postHandler(U);if(z.hasOnSendHook){const Y=await z.hooks.onSend(L,U);if(Y)return Y}return L??new Response("No response from handler",{status:204})}catch(L){return new Response("Internal Server Error",{status:500})}}class j{routes;globalMiddlewares;middlewares;trie;hasOnReqHook;hasMiddleware;hasPreHandlerHook;hasPostHandlerHook;hasOnSendHook;hooks;constructor(){this.routes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new V,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hooks={onRequest:null,preHandler:null,postHandler:null,onSend:null,onError:null,onClose:null}}addHooks(F,G){if(typeof F!=="string")throw new Error("hookName must be a string");if(typeof G!=="function")throw new Error("callback must be a instance of function");if(this.hooks.hasOwnProperty(F))this.hooks[F]=G;else throw new Error(`Unknown hook type: ${F}`)}compile(){if(this.globalMiddlewares.length>0)this.hasMiddleware=!0;for(let[F,G]of this.middlewares.entries())if(G.length>0){this.hasMiddleware=!0;break}if(this.hooks.onRequest)this.hasOnReqHook=!0;if(this.hooks.preHandler)this.hasPreHandlerHook=!0;if(this.hooks.postHandler)this.hasPostHandlerHook=!0;if(this.hooks.onSend)this.hasOnSendHook=!0}listen(F,G,{sslCert:z=null,sslKey:U=null}={}){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");if(typeof F!=="number")throw new Error("Port must be a numeric value");this.compile();const J={port:F,fetch:async(Y)=>{const $=new URL(Y.url);try{return await K(Y,$,this)}catch(W){return new Response("Internal Server Error",{status:500})}},onClose(){console.log("Server is shutting down...")}};if(z&&U)J.certFile=z,J.keyFile=U;const L=Bun.serve(J);if(typeof G==="function")return G();if(z&&U)console.log(`HTTPS server is running on https://localhost:${F}`);else console.log(`HTTP server is running on http://localhost:${F}`);return L}register(F,G){if(typeof F!=="string")throw new Error("path must be a string");if(typeof G!=="object")throw new Error("handler parameter should be a instance of router object",G);const z=Object.entries(G.trie.root.children);G.trie.root.subMiddlewares.forEach((U,J)=>{if(!this.middlewares.has(F+J))this.middlewares.set(F+J,[]);U?.forEach((L)=>{if(!this.middlewares.get(F+J)?.includes(L))this.middlewares.get(F+J)?.push(L)})});for(let[U,J]of z){const L=F+J?.path,Y=J.handler[0],$=J.method[0];this.trie.insert(L,{handler:Y,method:$})}G.trie=new V}#z(F,G,z){if(typeof G!=="string")throw new Error("Path must be a string type");if(typeof F!=="string")throw new Error("method must be a string type");const U=z.slice(0,-1),J=z[z.length-1];if(!this.middlewares.has(G))this.middlewares.set(G,[]);U.forEach((L)=>{if(G==="/"){if(!this.globalMiddlewares.includes(L))this.globalMiddlewares.push(L)}else if(!this.middlewares.get(G)?.includes(L))this.middlewares.get(G)?.push(L)}),this.trie.insert(G,{handler:J,method:F})}use(F,G){if(typeof F==="function"){if(!this.globalMiddlewares.includes(F))return this.globalMiddlewares.push(F)}const z=F;if(!this.middlewares.has(z))this.middlewares.set(z,[]);if(!this.middlewares.get(z)?.includes(G))this.middlewares.get(z)?.push(G)}get(F,...G){return this.#z("GET",F,G),this}post(F,...G){return this.#z("POST",F,G),this}put(F,...G){return this.#z("PUT",F,G),this}patch(F,...G){return this.#z("PATCH",F,G),this}delete(F,...G){return this.#z("DELETE",F,G),this}}var g=j;export{g as default};
package/dist/router.js CHANGED
@@ -1 +1 @@
1
- var C=(J,L)=>()=>(L||J((L={exports:{}}).exports,L),L.exports);var y=C((R)=>{Object.defineProperty(R,"__esModule",{value:!0});class S{constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class w{constructor(){this.root=new S}insert(J,L){let z=this.root;const U=J.split("/").filter(Boolean);if(J==="/"){z.isEndOfWord=!0,z.handler.push(L.handler),z.path=J,z.method.push(L.method);return}for(let Y of U){let X=!1,Z=Y;if(Y.startsWith(":"))X=!0,Z=":";if(!z.children[Z])z.children[Z]=new S;z=z.children[Z],z.isDynamic=X,z.pattern=Y}z.isEndOfWord=!0,z.method.push(L.method),z.handler.push(L.handler),z.path=J}search(J,L){let z=this.root;const U=J.split("/").filter(Boolean);for(let X of U){let Z=X;if(!z.children[Z])if(z.children[":"])z=z.children[":"];else return null;else z=z.children[Z]}let Y=z.method.indexOf(L);if(Y!==-1)return{path:z.path,handler:z.handler[Y],isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[Y]};return{path:z.path,handler:z.handler,isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[Y]}}}R.default=w});var P=C((b)=>{function p(J,L){let z={},U={},Y=!1,X=null,Z=null,W=null,Q,V=200;return{req:J,url:L,next:()=>{},status($){return V=$,this},body(){return O(this,void 0,void 0,function*(){if(!Q)Q=yield l(J);if(Q.error)return new Response(JSON.stringify({error:Q.error}),{status:400,headers:{"Content-Type":"application/json"}});return Q})},setHeader($,E){return z[$]=E,this},set($,E){return U[$]=E,this},get($){return U[$]||null},setAuth($){return Y=$,this},getAuth(){return Y},text($,E){if(E)V=E;return new Response($,{status:V,headers:z})},json($,E){if(E)V=E;return new Response(JSON.stringify($),{status:V,headers:Object.assign({"Content-Type":"application/json"},z)})},html($,E){if(E)V=E;return new Response(Bun.file($),{status:V,headers:Object.assign({},z)})},file($,E){if(E)V=E;return new Response(Bun.file($),{status:V,headers:Object.assign({},z)})},redirect($,E){if(E)V=E;return new Response(null,{status:V,headers:Object.assign({Location:$},z)})},getParams($){if(!W)W=n(J===null||J===void 0?void 0:J.routePattern,L===null||L===void 0?void 0:L.pathname);return $?W[$]||null:W},getQuery($){if(!X)X=Object.fromEntries(L.searchParams);return $?X[$]||null:X},cookie($,E){return O(this,arguments,void 0,function*(c,h,B={}){let K=`${encodeURIComponent(c)}=${encodeURIComponent(h)}`;if(B.maxAge)K+=`; Max-Age=${B.maxAge}`;if(B.expires)K+=`; Expires=${B.expires.toUTCString()}`;if(B.path)K+=`; Path=${B.path}`;if(B.domain)K+=`; Domain=${B.domain}`;if(B.secure)K+="; Secure";if(B.httpOnly)K+="; HttpOnly";if(B.sameSite)K+=`; SameSite=${B.sameSite}`;if(z["Set-Cookie"]){const q=Array.isArray(z["Set-Cookie"])?z["Set-Cookie"]:[z["Set-Cookie"]];q.push(K),z["Set-Cookie"]=q}else z["Set-Cookie"]=K;return this})},getCookie($){return O(this,void 0,void 0,function*(){if(!Z){const E=J.headers.get("cookie");if(E)Z=yield i(E)}return $?Z[$]||null:Z})}}}function i(J){return O(this,void 0,void 0,function*(){const L={};if(!J)return L;return J.split(";").forEach((U)=>{var Y;const[X,Z]=(Y=U===null||U===void 0?void 0:U.trim())===null||Y===void 0?void 0:Y.split("=");if(X&&Z)L[X.trim()]=Z.split(" ")[0].trim()}),L})}function n(J,L){const z={},U=J.split("/"),[Y]=L.split("?"),X=Y.split("/");if(U.length!==X.length)return null;return U.forEach((Z,W)=>{if(Z.startsWith(":")){const Q=Z.slice(1);z[Q]=X[W]}}),z}function l(J){return O(this,void 0,void 0,function*(){const L=J.headers.get("Content-Type")||"";if(!L)return{};try{if(L.startsWith("application/json"))return yield J.json();if(L.startsWith("application/x-www-form-urlencoded")){const z=yield J.text();return Object.fromEntries(new URLSearchParams(z))}if(L.startsWith("multipart/form-data")){const z=yield J.formData();return d(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}})}function d(J){const L={};for(let[z,U]of J.entries())L[z]=U;return L}var O=b&&b.__awaiter||function(J,L,z,U){function Y(X){return X instanceof z?X:new z(function(Z){Z(X)})}return new(z||(z=Promise))(function(X,Z){function W($){try{V(U.next($))}catch(E){Z(E)}}function Q($){try{V(U.throw($))}catch(E){Z(E)}}function V($){$.done?X($.value):Y($.value).then(W,Q)}V((U=U.apply(J,L||[])).next())})};Object.defineProperty(b,"__esModule",{value:!0});b.default=p});var g=C((G)=>{function a(J,L,z){return x(this,void 0,void 0,function*(){const U=s.default(J,L);if(z.hasOnReqHook)yield z.hooks.onRequest(U);if(z.hasMiddleware){const X=[...z.globalMiddlewares,...z.middlewares.get(L.pathname)||[]],Z=yield r(X,U);if(Z)return Z}let Y;if(H[L.pathname+J.method])Y=H[L.pathname+J.method];else Y=z.trie.search(L.pathname,J.method),H[L.pathname+J.method]=Y;if(!Y||!Y.handler)return new Response(`Route not found for ${L.pathname}`,{status:404});if(Y.method!==J.method)return new Response("Method not allowed",{status:405});if(Y.isDynamic)J.routePattern=Y.path;if(z.hasPreHandlerHook){const X=yield z.hooks.preHandler(U);if(X)return X}try{const X=yield Y.handler(U);if(z.hasPostHandlerHook)yield z.hooks.postHandler(U);if(z.hasOnSendHook){const Z=yield z.hooks.onSend(X,U);if(Z)return Z}return X!==null&&X!==void 0?X:new Response("No response from handler",{status:204})}catch(X){return new Response("Internal Server Error",{status:500})}})}function r(J,L){return x(this,void 0,void 0,function*(){for(let z of J){const U=yield z(L);if(U)return U}})}var x=G&&G.__awaiter||function(J,L,z,U){function Y(X){return X instanceof z?X:new z(function(Z){Z(X)})}return new(z||(z=Promise))(function(X,Z){function W($){try{V(U.next($))}catch(E){Z(E)}}function Q($){try{V(U.throw($))}catch(E){Z(E)}}function V($){$.done?X($.value):Y($.value).then(W,Q)}V((U=U.apply(J,L||[])).next())})},o=G&&G.__importDefault||function(J){return J&&J.__esModule?J:{default:J}};Object.defineProperty(G,"__esModule",{value:!0});G.default=a;var s=o(P()),H={}});var m=C((A)=>{var t=A&&A.__awaiter||function(J,L,z,U){function Y(X){return X instanceof z?X:new z(function(Z){Z(X)})}return new(z||(z=Promise))(function(X,Z){function W($){try{V(U.next($))}catch(E){Z(E)}}function Q($){try{V(U.throw($))}catch(E){Z(E)}}function V($){$.done?X($.value):Y($.value).then(W,Q)}V((U=U.apply(J,L||[])).next())})},j=A&&A.__classPrivateFieldGet||function(J,L,z,U){if(z==="a"&&!U)throw new TypeError("Private accessor was defined without a getter");if(typeof L==="function"?J!==L||!U:!L.has(J))throw new TypeError("Cannot read private member from an object whose class did not declare it");return z==="m"?U:z==="a"?U.call(J):U?U.value:L.get(J)},v=A&&A.__importDefault||function(J){return J&&J.__esModule?J:{default:J}},F,I;Object.defineProperty(A,"__esModule",{value:!0});var f=v(y()),e=v(g());class k{constructor(){F.add(this),this.routes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new f.default,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hooks={onRequest:null,preHandler:null,postHandler:null,onSend:null,onError:null,onClose:null}}addHooks(J,L){if(typeof J!=="string")throw new Error("hookName must be a string");if(typeof L!=="function")throw new Error("callback must be a instance of function");if(this.hooks.hasOwnProperty(J))this.hooks[J]=L;else throw new Error(`Unknown hook type: ${J}`)}compile(){if(this.globalMiddlewares.length>0)this.hasMiddleware=!0;for(let[J,L]of this.middlewares.entries())if(L.length>0){this.hasMiddleware=!0;break}if(this.hooks.onRequest)this.hasOnReqHook=!0;if(this.hooks.preHandler)this.hasPreHandlerHook=!0;if(this.hooks.postHandler)this.hasPostHandlerHook=!0;if(this.hooks.onSend)this.hasOnSendHook=!0}listen(J,L,{sslCert:z=null,sslKey:U=null}={}){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");if(typeof J!=="number")throw new Error("Port must be a numeric value");this.compile();const Y={port:J,fetch:(Z)=>t(this,void 0,void 0,function*(){const W=new URL(Z.url);try{return yield e.default(Z,W,this)}catch(Q){return new Response("Internal Server Error",{status:500})}}),onClose(){console.log("Server is shutting down...")}};if(z&&U)Y.certFile=z,Y.keyFile=U;const X=Bun.serve(Y);if(typeof L==="function")return L();if(z&&U)console.log(`HTTPS server is running on https://localhost:${J}`);else console.log(`HTTP server is running on http://localhost:${J}`);return X}register(J,L){if(typeof J!=="string")throw new Error("path must be a string");if(typeof L!=="object")throw new Error("handler parameter should be a instance of router object",L);const z=Object.entries(L.trie.root.children);L.trie.root.subMiddlewares.forEach((U,Y)=>{if(!this.middlewares.has(J+Y))this.middlewares.set(J+Y,[]);U===null||U===void 0||U.forEach((X)=>{var Z,W;if(!((Z=this.middlewares.get(J+Y))===null||Z===void 0?void 0:Z.includes(X)))(W=this.middlewares.get(J+Y))===null||W===void 0||W.push(X)})});for(let[U,Y]of z){const X=J+(Y===null||Y===void 0?void 0:Y.path),Z=Y.handler[0],W=Y.method[0];this.trie.insert(X,{handler:Z,method:W})}L.trie=new f.default}use(J,L){var z,U;if(typeof J==="function"){if(!this.globalMiddlewares.includes(J))return this.globalMiddlewares.push(J)}const Y=J;if(!this.middlewares.has(Y))this.middlewares.set(Y,[]);if(!((z=this.middlewares.get(Y))===null||z===void 0?void 0:z.includes(L)))(U=this.middlewares.get(Y))===null||U===void 0||U.push(L)}get(J,...L){return j(this,F,"m",I).call(this,"GET",J,L),this}post(J,...L){return j(this,F,"m",I).call(this,"POST",J,L),this}put(J,...L){return j(this,F,"m",I).call(this,"PUT",J,L),this}patch(J,...L){return j(this,F,"m",I).call(this,"PATCH",J,L),this}delete(J,...L){return j(this,F,"m",I).call(this,"DELETE",J,L),this}}F=new WeakSet,I=function J(L,z,U){if(typeof z!=="string")throw new Error("Path must be a string type");if(typeof L!=="string")throw new Error("method must be a string type");const Y=U.slice(0,-1),X=U[U.length-1];if(!this.middlewares.has(z))this.middlewares.set(z,[]);Y.forEach((Z)=>{var W,Q;if(z==="/"){if(!this.globalMiddlewares.includes(Z))this.globalMiddlewares.push(Z)}else if(!((W=this.middlewares.get(z))===null||W===void 0?void 0:W.includes(Z)))(Q=this.middlewares.get(z))===null||Q===void 0||Q.push(Z)}),this.trie.insert(z,{handler:X,method:L})};A.default=k});var Lz=C((M)=>{var D=M&&M.__classPrivateFieldGet||function(J,L,z,U){if(z==="a"&&!U)throw new TypeError("Private accessor was defined without a getter");if(typeof L==="function"?J!==L||!U:!L.has(J))throw new TypeError("Cannot read private member from an object whose class did not declare it");return z==="m"?U:z==="a"?U.call(J):U?U.value:L.get(J)},zz=M&&M.__importDefault||function(J){return J&&J.__esModule?J:{default:J}},T,N;Object.defineProperty(M,"__esModule",{value:!0});var Jz=zz(m());class _ extends Jz.default{constructor(){super();T.add(this)}get(J,...L){return D(this,T,"m",N).call(this,"GET",J,L),this}post(J,...L){return D(this,T,"m",N).call(this,"POST",J,L),this}put(J,...L){return D(this,T,"m",N).call(this,"PUT",J,L),this}patch(J,...L){return D(this,T,"m",N).call(this,"PATCH",J,L),this}delete(J,...L){return D(this,T,"m",N).call(this,"DELETE",J,L),this}}T=new WeakSet,N=function J(L,z,U){if(!this.trie.root.subMiddlewares.has(z))this.trie.root.subMiddlewares.set(z,[]);const Y=U.slice(0,-1),X=this.trie.root.subMiddlewares.get(z);Y.forEach((W)=>{if(!(X===null||X===void 0?void 0:X.includes(W)))X===null||X===void 0||X.push(W)});const Z=U[U.length-1];this.trie.insert(z,{handler:Z,method:L})};M.default=_});export default Lz();
1
+ class Q{children;isEndOfWord;handler;isDynamic;pattern;path;method;subMiddlewares;constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class V{root;constructor(){this.root=new Q}insert(G,F){let z=this.root;const U=G.split("/").filter(Boolean);if(G==="/"){z.isEndOfWord=!0,z.handler.push(F.handler),z.path=G,z.method.push(F.method);return}for(let J of U){let L=!1,Y=J;if(J.startsWith(":"))L=!0,Y=":";if(!z.children[Y])z.children[Y]=new Q;z=z.children[Y],z.isDynamic=L,z.pattern=J}z.isEndOfWord=!0,z.method.push(F.method),z.handler.push(F.handler),z.path=G}search(G,F){let z=this.root;const U=G.split("/").filter(Boolean);for(let L of U){let Y=L;if(!z.children[Y])if(z.children[":"])z=z.children[":"];else return null;else z=z.children[Y]}let J=z.method.indexOf(F);if(J!==-1)return{path:z.path,handler:z.handler[J],isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[J]};return{path:z.path,handler:z.handler,isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[J]}}}async function T(G){const F={};if(!G)return F;return G.split(";").forEach((U)=>{const[J,L]=U?.trim()?.split("=");if(J&&L)F[J.trim()]=L.split(" ")[0].trim()}),F}function b(G,F){const z={},U=G.split("/"),[J]=F.split("?"),L=J.split("/");if(U.length!==L.length)return null;return U.forEach((Y,$)=>{if(Y.startsWith(":")){const W=Y.slice(1);z[W]=L[$]}}),z}async function N(G){const F=G.headers.get("Content-Type")||"";if(!F)return{};try{if(F.startsWith("application/json"))return await G.json();if(F.startsWith("application/x-www-form-urlencoded")){const z=await G.text();return Object.fromEntries(new URLSearchParams(z))}if(F.startsWith("multipart/form-data")){const z=await G.formData();return I(z)}return{error:"Unknown request body type"}}catch(z){return{error:"Invalid request body format"}}}function I(G){const F={};for(let[z,U]of G.entries())F[z]=U;return F}function B(G,F){let z=new Headers,U={},J=!1,L=null,Y=null,$=null,W,E=200;return{req:G,url:F,next:()=>{},status(X){return E=X,this},async body(){if(!W)W=await N(G);if(W.error)return new Response(JSON.stringify({error:W.error}),{status:400});return W},setHeader(X,Z){return z.set(X,Z),this},set(X,Z){return U[X]=Z,this},get(X){return U[X]||null},setAuth(X){return J=X,this},getAuth(){return J},text(X,Z){return new Response(X,{status:Z??E,headers:z})},json(X,Z){return new Response(JSON.stringify(X),{status:Z??E,headers:z})},html(X,Z){return new Response(Bun.file(X),{status:Z??E,headers:z})},file(X,Z){return new Response(Bun.file(X),{status:Z??E,headers:z})},redirect(X,Z){return z.set("Location",X),new Response(null,{status:Z??302,headers:z})},getParams(X){if(!$)$=b(G?.routePattern,F?.pathname);return X?$[X]||null:$},getQuery(X){if(!L)L=Object.fromEntries(F.searchParams);return X?L[X]||null:L},async cookie(X,Z,_={}){let A=`${encodeURIComponent(X)}=${encodeURIComponent(Z)}`;if(_.maxAge)A+=`; Max-Age=${_.maxAge}`;if(_.expires)A+=`; Expires=${_.expires.toUTCString()}`;if(_.path)A+=`; Path=${_.path}`;if(_.domain)A+=`; Domain=${_.domain}`;if(_.secure)A+="; Secure";if(_.httpOnly)A+="; HttpOnly";if(_.sameSite)A+=`; SameSite=${_.sameSite}`;return z?.append("Set-Cookie",A),this},async getCookie(X){if(!Y){const Z=G.headers.get("cookie");if(Z)Y=await T(Z)}return X?Y[X]||null:Y}}}async function C(G,F){for(let z of G){const U=await z(F);if(U)return U}}var K={};async function j(G,F,z){const U=B(G,F);if(z.hasOnReqHook)await z.hooks.onRequest(U);if(z.hasMiddleware){const L=[...z.globalMiddlewares,...z.middlewares.get(F.pathname)||[]],Y=await C(L,U);if(Y)return Y}let J;if(K[F.pathname+G.method])J=K[F.pathname+G.method];else J=z.trie.search(F.pathname,G.method),K[F.pathname+G.method]=J;if(!J||!J.handler)return new Response(`Route not found for ${F.pathname}`,{status:404});if(J.method!==G.method)return new Response("Method not allowed",{status:405});if(J.isDynamic)G.routePattern=J.path;if(z.hasPreHandlerHook){const L=await z.hooks.preHandler(U);if(L)return L}try{const L=await J.handler(U);if(z.hasPostHandlerHook)await z.hooks.postHandler(U);if(z.hasOnSendHook){const Y=await z.hooks.onSend(L,U);if(Y)return Y}return L??new Response("No response from handler",{status:204})}catch(L){return new Response("Internal Server Error",{status:500})}}class D{routes;globalMiddlewares;middlewares;trie;hasOnReqHook;hasMiddleware;hasPreHandlerHook;hasPostHandlerHook;hasOnSendHook;hooks;constructor(){this.routes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new V,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hooks={onRequest:null,preHandler:null,postHandler:null,onSend:null,onError:null,onClose:null}}addHooks(G,F){if(typeof G!=="string")throw new Error("hookName must be a string");if(typeof F!=="function")throw new Error("callback must be a instance of function");if(this.hooks.hasOwnProperty(G))this.hooks[G]=F;else throw new Error(`Unknown hook type: ${G}`)}compile(){if(this.globalMiddlewares.length>0)this.hasMiddleware=!0;for(let[G,F]of this.middlewares.entries())if(F.length>0){this.hasMiddleware=!0;break}if(this.hooks.onRequest)this.hasOnReqHook=!0;if(this.hooks.preHandler)this.hasPreHandlerHook=!0;if(this.hooks.postHandler)this.hasPostHandlerHook=!0;if(this.hooks.onSend)this.hasOnSendHook=!0}listen(G,F,{sslCert:z=null,sslKey:U=null}={}){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");if(typeof G!=="number")throw new Error("Port must be a numeric value");this.compile();const J={port:G,fetch:async(Y)=>{const $=new URL(Y.url);try{return await j(Y,$,this)}catch(W){return new Response("Internal Server Error",{status:500})}},onClose(){console.log("Server is shutting down...")}};if(z&&U)J.certFile=z,J.keyFile=U;const L=Bun.serve(J);if(typeof F==="function")return F();if(z&&U)console.log(`HTTPS server is running on https://localhost:${G}`);else console.log(`HTTP server is running on http://localhost:${G}`);return L}register(G,F){if(typeof G!=="string")throw new Error("path must be a string");if(typeof F!=="object")throw new Error("handler parameter should be a instance of router object",F);const z=Object.entries(F.trie.root.children);F.trie.root.subMiddlewares.forEach((U,J)=>{if(!this.middlewares.has(G+J))this.middlewares.set(G+J,[]);U?.forEach((L)=>{if(!this.middlewares.get(G+J)?.includes(L))this.middlewares.get(G+J)?.push(L)})});for(let[U,J]of z){const L=G+J?.path,Y=J.handler[0],$=J.method[0];this.trie.insert(L,{handler:Y,method:$})}F.trie=new V}#z(G,F,z){if(typeof F!=="string")throw new Error("Path must be a string type");if(typeof G!=="string")throw new Error("method must be a string type");const U=z.slice(0,-1),J=z[z.length-1];if(!this.middlewares.has(F))this.middlewares.set(F,[]);U.forEach((L)=>{if(F==="/"){if(!this.globalMiddlewares.includes(L))this.globalMiddlewares.push(L)}else if(!this.middlewares.get(F)?.includes(L))this.middlewares.get(F)?.push(L)}),this.trie.insert(F,{handler:J,method:G})}use(G,F){if(typeof G==="function"){if(!this.globalMiddlewares.includes(G))return this.globalMiddlewares.push(G)}const z=G;if(!this.middlewares.has(z))this.middlewares.set(z,[]);if(!this.middlewares.get(z)?.includes(F))this.middlewares.get(z)?.push(F)}get(G,...F){return this.#z("GET",G,F),this}post(G,...F){return this.#z("POST",G,F),this}put(G,...F){return this.#z("PUT",G,F),this}patch(G,...F){return this.#z("PATCH",G,F),this}delete(G,...F){return this.#z("DELETE",G,F),this}}var M=D;class v extends M{constructor(){super()}#z(G,F,z){if(!this.trie.root.subMiddlewares.has(F))this.trie.root.subMiddlewares.set(F,[]);const U=z.slice(0,-1),J=this.trie.root.subMiddlewares.get(F);U.forEach((Y)=>{if(!J?.includes(Y))J?.push(Y)});const L=z[z.length-1];this.trie.insert(F,{handler:L,method:G})}get(G,...F){return this.#z("GET",G,F),this}post(G,...F){return this.#z("POST",G,F),this}put(G,...F){return this.#z("PUT",G,F),this}patch(G,...F){return this.#z("PATCH",G,F),this}delete(G,...F){return this.#z("DELETE",G,F),this}}var f=v;export{f as default};
package/dist/trie.js CHANGED
@@ -1 +1 @@
1
- var H=(v,q)=>()=>(q||v((q={exports:{}}).exports,q),q.exports);var K=H((G)=>{Object.defineProperty(G,"__esModule",{value:!0});class C{constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class E{constructor(){this.root=new C}insert(v,q){let j=this.root;const B=v.split("/").filter(Boolean);if(v==="/"){j.isEndOfWord=!0,j.handler.push(q.handler),j.path=v,j.method.push(q.method);return}for(let w of B){let A=!1,z=w;if(w.startsWith(":"))A=!0,z=":";if(!j.children[z])j.children[z]=new C;j=j.children[z],j.isDynamic=A,j.pattern=w}j.isEndOfWord=!0,j.method.push(q.method),j.handler.push(q.handler),j.path=v}search(v,q){let j=this.root;const B=v.split("/").filter(Boolean);for(let A of B){let z=A;if(!j.children[z])if(j.children[":"])j=j.children[":"];else return null;else j=j.children[z]}let w=j.method.indexOf(q);if(w!==-1)return{path:j.path,handler:j.handler[w],isDynamic:j.isDynamic,pattern:j.pattern,method:j.method[w]};return{path:j.path,handler:j.handler,isDynamic:j.isDynamic,pattern:j.pattern,method:j.method[w]}}}G.default=E});export default K();
1
+ class C{children;isEndOfWord;handler;isDynamic;pattern;path;method;subMiddlewares;constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class E{root;constructor(){this.root=new C}insert(w,z){let b=this.root;const B=w.split("/").filter(Boolean);if(w==="/"){b.isEndOfWord=!0,b.handler.push(z.handler),b.path=w,b.method.push(z.method);return}for(let j of B){let A=!1,q=j;if(j.startsWith(":"))A=!0,q=":";if(!b.children[q])b.children[q]=new C;b=b.children[q],b.isDynamic=A,b.pattern=j}b.isEndOfWord=!0,b.method.push(z.method),b.handler.push(z.handler),b.path=w}search(w,z){let b=this.root;const B=w.split("/").filter(Boolean);for(let A of B){let q=A;if(!b.children[q])if(b.children[":"])b=b.children[":"];else return null;else b=b.children[q]}let j=b.method.indexOf(z);if(j!==-1)return{path:b.path,handler:b.handler[j],isDynamic:b.isDynamic,pattern:b.pattern,method:b.method[j]};return{path:b.path,handler:b.handler,isDynamic:b.isDynamic,pattern:b.pattern,method:b.method[j]}}}export{E as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "diesel-core",
3
- "version": "0.0.8",
4
- "main": "dist/server.js",
3
+ "version": "0.0.10",
4
+ "main": "dist/main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
7
7
  },
package/dist/server.js DELETED
@@ -1 +0,0 @@
1
- class B{constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[],this.subMiddlewares=new Map}}class V{constructor(){this.root=new B}insert(F,G){let z=this.root;const L=F.split("/").filter(Boolean);if(F==="/"){z.isEndOfWord=!0,z.handler.push(G.handler),z.path=F,z.method.push(G.method);return}for(let J of L){let U=!1,Y=J;if(J.startsWith(":"))U=!0,Y=":";if(!z.children[Y])z.children[Y]=new B;z=z.children[Y],z.isDynamic=U,z.pattern=J}z.isEndOfWord=!0,z.method.push(G.method),z.handler.push(G.handler),z.path=F}insertMidl(F){if(!this.root.subMiddlewares.has(F))this.root.subMiddlewares.set(F)}search(F,G){let z=this.root;const L=F.split("/").filter(Boolean);for(let U of L){let Y=U;if(!z.children[Y])if(z.children[":"])z=z.children[":"];else return null;else z=z.children[Y]}let J=z.method.indexOf(G);if(J!==-1)return{path:z.path,handler:z.handler[J],isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[J]};return{path:z.path,handler:z.handler,isDynamic:z.isDynamic,pattern:z.pattern,method:z.method[J]}}getAllRoutes(){const F=[],G=(z,L)=>{if(z.isEndOfWord)F.push({path:L,handler:z.handler,isImportant:z.isImportant,isDynamic:z.isDynamic,pattern:z.pattern});for(let J in z.children){const U=z.children[J],Y=L+(J===":"?"/:"+U.pattern:"/"+J);G(U,Y)}};return G(this.root,""),F}}async function b(F){const G={};if(!F)return G;return F.split(";").forEach((L)=>{const[J,U]=L.trim().split("=");G[J]=U.split(" ")[0]}),G}function v(F,G){const z={},L=F.split("/"),[J]=G.split("?"),U=J.split("/");if(L.length!==U.length)return null;return L.forEach((Y,E)=>{if(Y.startsWith(":")){const A=Y.slice(1);z[A]=U[E]}}),z}async function T(F){const G=F.headers.get("Content-Type")||"";if(!G)return{};try{if(G.startsWith("application/json"))return await F.json();if(G.startsWith("application/x-www-form-urlencoded")){const z=await F.text();return Object.fromEntries(new URLSearchParams(z))}if(G.startsWith("multipart/form-data")){const z=await F.formData();return N(z)}return new Response({error:"Unknown request body type"})}catch(z){return new Response({error:"Invalid request body format"})}}function N(F){const G={};for(let[z,L]of F.entries())G[z]=L;return G}function Q(F,G){let z={},L={},J=!1,U=null,Y=null,E=null,A=null,$=200;return{req:F,url:G,next:()=>{},status(X){return $=X,this},async body(){if(!A)A=await T(F);return A},setHeader(X,Z){return z[X]=Z,this},set(X,Z){return L[X]=Z,this},get(X){return L[X]},setAuth(X){return J=X,this},getAuth(){return J},text(X,Z){if(Z)$=Z;return new Response(X,{status:$,headers:z})},json(X,Z){if(Z)$=Z;return new Response(JSON.stringify(X),{status:$,headers:{"Content-Type":"application/json",...z}})},html(X,Z){if(Z)$=Z;return new Response(Bun.file(X),{status:$,headers:{...z}})},file(X,Z){if(Z)$=Z;return new Response(Bun.file(X),{status:$,headers:{...z}})},redirect(X,Z){if(Z)$=Z;return new Response(null,{status:$,headers:{Location:X,...z}})},getParams(X){if(!E)E=v(F.routePattern,G.pathname);return X?E[X]:E},getQuery(X){if(!U)U=Object.fromEntries(G.searchParams);return X?U[X]:U},async cookie(X,Z,_={}){let W=`${encodeURIComponent(X)}=${encodeURIComponent(Z)}`;if(_.maxAge)W+=`; Max-Age=${_.maxAge}`;if(_.expires)W+=`; Expires=${_.expires.toUTCString()}`;if(_.path)W+=`; Path=${_.path}`;if(_.domain)W+=`; Domain=${_.domain}`;if(_.secure)W+="; Secure";if(_.httpOnly)W+="; HttpOnly";if(_.sameSite)W+=`; SameSite=${_.sameSite}`;if(z["Set-Cookie"]){const K=Array.isArray(z["Set-Cookie"])?z["Set-Cookie"]:[z["Set-Cookie"]];K.push(W),z["Set-Cookie"]=K}else z["Set-Cookie"]=W;return this},async getCookie(X){if(!Y)Y=await b(F.headers.get("cookie"));return X?Y[X]:Y}}}async function I(F,G){for(let z of F){const L=await z(G);if(L)return L}}var M={};async function j(F,G,z){const L=Q(F,G);if(z.hasOnReqHook)await z.hooks.onRequest(L);if(z.hasMiddleware){const U=[...z.globalMiddlewares,...z.middlewares.get(G.pathname)||[]],Y=await I(U,L);if(Y)return Y}let J;if(M[G.pathname+F.method])J=M[G.pathname+F.method];else J=z.trie.search(G.pathname,F.method),M[G.pathname+F.method]=J;if(!J||!J.handler)return new Response(`Route not found for ${G.pathname}`,{status:404});if(J.method!==F.method)return new Response("Method not allowed",{status:405});if(J.isDynamic)F.routePattern=J.path;if(z.hasPreHandlerHook){const U=await z.hooks.preHandler(L);if(U)return U}try{const U=await J.handler(L);if(z.hasPostHandlerHook)await z.hooks.postHandler(L);if(z.hasOnSendHook){const Y=await z.hooks.onSend(U,L);if(Y)return Y}return U??new Response("No response from handler",{status:204})}catch(U){return new Response("Internal Server Error",{status:500})}}class D{constructor(){this.routes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new V,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hooks={onRequest:null,preHandler:null,postHandler:null,onSend:null,onError:null,onClose:null}}addHooks(F,G){if(typeof F!=="string")throw new Error("hookName must be a string");if(typeof G!=="function")throw new Error("callback must be a instance of function");if(this.hooks.hasOwnProperty(F))this.hooks[F]=G;else throw new Error(`Unknown hook type: ${F}`)}compile(){if(this.globalMiddlewares.length>0)this.hasMiddleware=!0;for(let[F,G]of this.middlewares.entries())if(G.length>0){this.hasMiddleware=!0;break}if(this.hooks.onRequest)this.hasOnReqHook=!0;if(this.hooks.preHandler)this.hasPreHandlerHook=!0;if(this.hooks.postHandler)this.hasPostHandlerHook=!0;if(this.hooks.onSend)this.hasOnSendHook=!0}listen(F,G,{sslCert:z=null,sslKey:L=null}={}){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");if(typeof F!=="number")throw new Error("Port must be a numeric value");this.compile();const J={port:F,fetch:async(Y)=>{const E=new URL(Y.url);try{return await j(Y,E,this)}catch(A){return new Response("Internal Server Error",{status:500})}},onClose(){console.log("Server is shutting down...")}};if(z&&L)J.certFile=z,J.keyFile=L;const U=Bun.serve(J);if(typeof G==="function")return G();if(z&&L)console.log(`HTTPS server is running on https://localhost:${F}`);else console.log(`HTTP server is running on http://localhost:${F}`);return U}register(F,G){if(typeof F!=="string")throw new Error("path must be a string");if(typeof G!=="object")throw new Error("handler parameter should be a instance of router object",G);const z=Object.entries(G.trie.root.children);G.trie.root.subMiddlewares.forEach((L,J)=>{if(!this.middlewares.has(F+J))this.middlewares.set(F+J,[]);if(!this.middlewares.get(F+J).includes(...L))this.middlewares.get(F+J).push(...L)});for(let[L,J]of z){const U=F+J?.path,Y=J.handler[0],E=J.method[0];this.trie.insert(U,{handler:Y,method:E})}G.trie=new V}#z(F,G,z){if(typeof G!=="string")throw new Error("Path must be a string type");if(typeof F!=="string")throw new Error("method must be a string type");const L=z.slice(0,-1);if(!this.middlewares.has(G))this.middlewares.set(G,[]);if(G==="/")L.forEach((U)=>{if(!this.globalMiddlewares.includes(U))this.globalMiddlewares.push(U)});else if(!this.middlewares.get(G).includes(...L))this.middlewares.get(G).push(...L);const J=z[z.length-1];this.trie.insert(G,{handler:J,method:F})}use(F,G){if(typeof F==="function"){if(!this.globalMiddlewares.includes(F))return this.globalMiddlewares.push(F)}const z=F;if(!this.middlewares.has(z))this.middlewares.set(z,[]);if(!this.middlewares.get(z).includes(G))this.middlewares.get(z).push(G)}get(F,...G){return this.#z("GET",F,G),this}post(F,...G){return this.#z("POST",F,G),this}put(F,...G){return this.#z("PUT",F,G),this}patch(F,...G){return this.#z("PATCH",F,G),this}delete(F,...G){return this.#z("DELETE",F,G),this}}var H=D;export{H as default};