diesel-core 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.ts CHANGED
@@ -70,8 +70,9 @@ export default class Diesel {
70
70
  /**
71
71
  * Mount method
72
72
  * we can use 3rd party framework with diesel.js
73
+ * or we can use it for sub routing also , even i recommend using mount or sub for sub routing
73
74
  */
74
- mount(prefix: string, fetch: DieselFetchHandler): void;
75
+ mount(prefix: string, instance: Diesel | DieselFetchHandler): void;
75
76
  /**
76
77
  * Registers a router instance for subrouting.
77
78
  * Allows defining subroutes like:
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var B={reset:"\x1B[0m",info:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",method:{GET:"\x1B[32m",POST:"\x1B[34m",PUT:"\x1B[35m",DELETE:"\x1B[31m",PATCH:"\x1B[36m"}},g=($,z,X)=>{let Z=B[$]||B.reset,Q=X?.method?B.method[X.method]||B.reset:B.reset,V=X?.status?X.status>=500?B.error:X.status>=400?B.warn:B.info:B.reset;console.log(`
2
2
  ${Z}[${$.toUpperCase()}]${B.reset} ${z} - ${Q}${X?.method||""}${B.reset}`);let G={timestamp:new Date().toISOString(),...X,status:X?.status?`${V}${X.status}${B.reset}`:void 0,method:X?.method?`${Q>Z}${X.method}${B.reset}`:void 0};console.log(JSON.stringify(G,null,2)+`
3
- `)},p=($)=>{let{app:z,logger:X,logLevel:Z="info",onRequest:Q,onSend:V,onError:G}=$||{};z?.addHooks("onRequest",(U)=>{U.req.startTime=Date.now(),X?.()??g(Z,"Incoming Request",{method:U.req.method,url:U.path,headers:{"user-agent":U.req.headers.get("user-agent"),"content-type":U.req.headers.get("content-type")}}),Q?.(U)}),z?.addHooks("onSend",async(U,W)=>{let F=`${Date.now()-U.req.startTime}ms`;X?.()??g(Z,"Response Sent",{method:U.req.method,url:U.url.toString(),status:W.status,duration:F,reqId:U.get?.("requestId"),headers:{"content-type":W.headers.get("content-type")}});let Y=await V?.(U);if(Y instanceof Response)return Y}),z?.addHooks("onError",async(U,W,F)=>{X?.()??g("error","Unhandled Error",{method:F.method,url:W,status:500,error:U.message});let Y=await G?.(U,W,F);if(Y instanceof Response)return Y})},v=($,z,X,Z=0,Q,V)=>{let G=B.method[z]||B.reset,U=Z>=500?B.error:Z>=400?B.warn:B.info,W=V?`[${V}] `:"",F=$==="<--"?`${$} ${G}${z}${B.reset} ${X} ${W}`:`${$} ${G}${z}${B.reset} ${X} ${U}${Z}${B.reset} ${Q??""} ${W}`;console.log(F)},F$=($)=>{let z=Date.now()-$;return z<1000?`${z}ms`:`${Math.round(z/1000)}s`},i=($)=>{let{app:z,log:X,onRequest:Z,onSend:Q,onError:V}=$;z.addHooks("onRequest",(G)=>{let{req:U,path:W}=G;U.startTime=Date.now(),X?.()??v("<--",U.method,W),Z?.(U,W)}),z.addHooks("onSend",async(G,U)=>{let{method:W,url:F}=G.req,Y=new URL(F).pathname,R=G.get?.("requestId");X?.()??v("-->",W,Y,U?.status,F$(G.req.startTime),R);let L=await Q?.(G);return L instanceof Response?L:U}),z.addHooks("onError",async(G,U,W)=>{let F=W.path;X?.()??v(G.message,W.method,F,500);let Y=await V?.(G,F,W);if(Y instanceof Response)return Y})};function l($,z){if(!$)throw Error("JWT library is not defined, please provide jwt to authenticateJwt Function");return(X)=>{try{let Z=X.cookies?.accessToken??X.req?.headers?.get("Authorization");if(!Z)return X.json({message:"Unauthorized",error:"No token provided"},401);if(Z.startsWith("Bearer "))Z=Z.slice(7);let Q=$?.verify(Z,z);if(!Q)return X.json({message:"Unauthorized",error:"Token could not be decoded"},401);X.set("user",Q)}catch(Z){let Q="Invalid token";if(Z.name==="TokenExpiredError")Q="Token expired";else if(Z.name==="JsonWebTokenError")Q="Malformed or tampered token";return X.json({message:"Unauthorized",error:Q},401)}}}function n($,z,X){if(!$)throw Error("JWT library is not defined, please provide jwt to authenticateJwtDB Function");if(!z)throw Error("User model is not defined, please provide UserModel to authenticateJwtDB Function");return async(Z)=>{try{let Q=Z.cookies?.accessToken??Z.req?.headers?.get("Authorization");if(!Q)return Z.json({message:"Unauthorized",error:"No token provided"},401);if(Q.startsWith("Bearer "))Q=Q.slice(7);let V=$?.verify(Q,X);if(!V)return Z.json({message:"Unauthorized",error:"Token could not be decoded"},401);let G=await z.findById(V._id).select("-password -refreshToken");if(!G)return Z.json({message:"Unauthorized: User not found"},404);Z.set("user",G);return}catch(Q){let V="Invalid token";if(Q.name==="TokenExpiredError")V="Token expired";else if(Q.name==="JsonWebTokenError")V="Malformed or tampered token";return Z.json({message:"Unauthorized",error:V},401)}}}function A($){switch($.split(".").pop()?.toLowerCase()){case"js":return"application/javascript";case"css":return"text/css";case"html":return"text/html";case"json":return"application/json";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"svg":return"image/svg+xml";case"gif":return"image/gif";case"woff":return"font/woff";case"woff2":return"font/woff2";default:return"application/octet-stream"}}var s=["GET","POST","PUT","PATCH","DELETE","ANY","ALL","HEAD","OPTIONS","PROPFIND"],D=Object.freeze({});class M{req;server;path;param;env;executionContext;headers;parsedQuery=null;parsedCookies=null;parsedBody=null;contextData=D;urlObject=null;constructor($,z,X,Z,Q,V){this.req=$,this.server=z,this.path=X,this.param=Z,this.env=Q,this.executionContext=V,this.headers=null}setHeader($,z){if(!this.headers)this.headers=new Headers;return this.headers.set($,z),this}removeHeader($){if(this.headers)this.headers.delete($);return this}set($,z){if(this.contextData===D)this.contextData={};return this.contextData[$]=z,this}get($){if(this.contextData===D)return;return this.contextData[$]}get ip(){if(this.server)return this.server.requestIP(this.req)?.address??null;return this.req.headers.get("CF-Connecting-IP")||null}get url(){if(!this.urlObject)this.urlObject=new URL(this.req.url);return this.urlObject}get query(){if(!this.parsedQuery)this.parsedQuery=this.url.search?Object.fromEntries(this.url.searchParams):D;return this.parsedQuery}get params(){return this.param?this.param:D}get body(){if(this.req.method==="GET")return Promise.resolve(D);if(!this.parsedBody)this.parsedBody=(async()=>{try{let $=await Y$(this.req);if($.error)throw Error($.error);return Object.keys($).length===0?null:$}catch($){throw Error("Invalid request body format")}})();return this.parsedBody}text($,z=200,X){if(!this.headers){if(!X)return new Response($,{status:z,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Z={"Content-Type":"text/plain; charset=utf-8"};return E(X,Z),new Response($,{status:z,headers:Z})}if(X)H(this.headers,X);if(!this.headers?.has("Content-Type"))this.headers?.set("Content-Type","text/plain; charset=utf-8");return new Response($,{status:z,headers:this.headers})}send($,z=200,X){let Z,Q;if($ instanceof Uint8Array||$ instanceof ArrayBuffer)Z="application/octet-stream",Q=$;else if($!==null&&typeof $==="object")Z="application/json; charset=utf-8",Q=JSON.stringify($);else if(typeof $==="string")Z="text/plain; charset=utf-8",Q=$;else Z="text/plain; charset=utf-8",Q=String($);if(!this.headers){if(!X)return new Response(Q,{status:z,headers:{"Content-Type":Z}});let V={"Content-Type":Z};return E(X,V),new Response(Q,{status:z,headers:V})}if(X)H(this.headers,X);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",Z);return new Response(Q,{status:z,headers:this.headers})}json($,z=200,X){if(!this.headers){if(!X)return Response.json($,{status:z,headers:{"Content-Type":"application/json; charset=utf-8"}});let Z={"Content-Type":"application/json; charset=utf-8"};return E(X,Z),Response.json($,{status:z,headers:Z})}if(X)H(this.headers,X);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return new Response(JSON.stringify($),{status:z,headers:this.headers})}file($,z,X=200,Z){let Q=Bun.file($);if(!this.headers){if(!Z)return new Response(Q,{status:X,headers:{"Content-Type":z??A($)}});let V={"Content-Type":z??A($)};return E(Z,V),new Response(Q,{status:X,headers:V})}if(Z)H(this.headers,Z);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",z??A($));return new Response(Q,{status:X,headers:this.headers})}async ejs($,z={},X=200){console.log("this method is diabled now for some time")}redirect($,z=302){if(!this.headers)this.headers=new Headers;return this.headers.set("Location",$),new Response(null,{status:z,headers:this.headers})}setCookie($,z,X={}){if(!this.headers)this.headers=new Headers;let Z=`${encodeURIComponent($)}=${encodeURIComponent(z)}`;if(X.maxAge)Z+=`; Max-Age=${X.maxAge}`;if(X.expires)Z+=`; Expires=${X.expires.toUTCString()}`;if(X.path)Z+=`; Path=${X.path}`;if(X.domain)Z+=`; Domain=${X.domain}`;if(X.secure)Z+="; Secure";if(X.httpOnly)Z+="; HttpOnly";if(X.sameSite)Z+=`; SameSite=${X.sameSite}`;return this.headers.append("Set-Cookie",Z),this}get cookies(){if(!this.parsedCookies){let $=this.req.headers.get("cookie");this.parsedCookies=$?J$($):D}return this.parsedCookies}stream($){let z=new Headers(this.headers??new Headers),X=new ReadableStream({async start(Z){await $(Z),Z.close()}});return new Response(X,{headers:z})}yieldStream($){return new Response}}function H($,z){for(let X in z)$.set(X,z[X])}function E($,z){for(let X in $)z[X]=$[X]}function J$($){return Object.fromEntries($.split(";").map((z)=>{let[X,...Z]=z.trim().split("=");return[X,decodeURIComponent(Z.join("="))]}))}async function Y$($){let z=$.headers.get("Content-Type")||"";if(!z)return{};if($.headers.get("Content-Length")==="0"||!$.body)return{};if(z.startsWith("application/json"))return await $.json();if(z.startsWith("application/x-www-form-urlencoded")){let Z=await $.text();return Object.fromEntries(new URLSearchParams(Z))}if(z.startsWith("multipart/form-data")){let Z=await $.formData(),Q={};for(let[V,G]of Z.entries())Q[V]=G;return Q}return{error:"Unknown request body type"}}var S=($)=>$!==null&&typeof $==="object"&&typeof $.then==="function",x=($)=>$!==null&&typeof $==="object"&&typeof $.status==="number"&&typeof $.headers==="object";async function C($,z,X){if(!z?.length)return;for(let Z=0;Z<z.length;Z++){let Q=z[Z](...X),V=Q instanceof Promise?await Q:Q;if(V&&$!=="onRequest")return V}}async function r($,z,X){for(let Z of $){let Q=await Z(z,X);if(Q)return Q}}async function a($,z,X){let Z=await B$($,z,X),Q=S(Z)?await Z:Z;if(Q)return Q}async function B$($,z,X){if(z.endsWith("/"))z=z.slice(0,-1);if(!$.filters.has(z))if($.filterFunction.length)for(let Z of $.filterFunction){let Q=await Z(X);if(Q)return Q}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function b($,z,X){if($.staticPath){let U=!0;if($.staticRequestPath)U=X.startsWith($.staticRequestPath);if(U){let W=await K$($,X,z);if(W)return W}}let V=($.router.find(z.req.method,"*")?.handler).slice(-1);if(V.length>0){let U=await V[0](z);if(x(U))return U}let G=await Promise.resolve($.routeNotFoundFunc(z));return x(G)?G:y(404,`404 Route not found for ${X}`)}function y($,z){return new Response(JSON.stringify({error:z}),{status:$,headers:{"Content-Type":"application/json"}})}async function K$($,z,X){if(!$.staticPath)return null;let Z=`${$.staticPath}${z}`;if(await Bun.file(Z).exists()){let V=A(Z);return X.file(Z,V,200)}return null}var c=($)=>$.constructor.name==="AsyncFunction",t=($,z,X,...Z)=>{if(z.length>5)$.push(`
3
+ `)},p=($)=>{let{app:z,logger:X,logLevel:Z="info",onRequest:Q,onSend:V,onError:G}=$||{};z?.addHooks("onRequest",(U)=>{U.req.startTime=Date.now(),X?.()??g(Z,"Incoming Request",{method:U.req.method,url:U.path,headers:{"user-agent":U.req.headers.get("user-agent"),"content-type":U.req.headers.get("content-type")}}),Q?.(U)}),z?.addHooks("onSend",async(U,W)=>{let F=`${Date.now()-U.req.startTime}ms`;X?.()??g(Z,"Response Sent",{method:U.req.method,url:U.url.toString(),status:W.status,duration:F,reqId:U.get?.("requestId"),headers:{"content-type":W.headers.get("content-type")}});let Y=await V?.(U);if(Y instanceof Response)return Y}),z?.addHooks("onError",async(U,W,F)=>{X?.()??g("error","Unhandled Error",{method:F.method,url:W,status:500,error:U.message});let Y=await G?.(U,W,F);if(Y instanceof Response)return Y})},v=($,z,X,Z=0,Q,V)=>{let G=B.method[z]||B.reset,U=Z>=500?B.error:Z>=400?B.warn:B.info,W=V?`[${V}] `:"",F=$==="<--"?`${$} ${G}${z}${B.reset} ${X} ${W}`:`${$} ${G}${z}${B.reset} ${X} ${U}${Z}${B.reset} ${Q??""} ${W}`;console.log(F)},F$=($)=>{let z=Date.now()-$;return z<1000?`${z}ms`:`${Math.round(z/1000)}s`},i=($)=>{let{app:z,log:X,onRequest:Z,onSend:Q,onError:V}=$;z.addHooks("onRequest",(G)=>{let{req:U,path:W}=G;U.startTime=Date.now(),X?.()??v("<--",U.method,W),Z?.(U,W)}),z.addHooks("onSend",async(G,U)=>{let{method:W,url:F}=G.req,Y=new URL(F).pathname,R=G.get?.("requestId");X?.()??v("-->",W,Y,U?.status,F$(G.req.startTime),R);let L=await Q?.(G);return L instanceof Response?L:U}),z.addHooks("onError",async(G,U,W)=>{let F=W.path;X?.()??v(G.message,W.method,F,500);let Y=await V?.(G,F,W);if(Y instanceof Response)return Y})};function l($,z){if(!$)throw Error("JWT library is not defined, please provide jwt to authenticateJwt Function");return(X)=>{try{let Z=X.cookies?.accessToken??X.req?.headers?.get("Authorization");if(!Z)return X.json({message:"Unauthorized",error:"No token provided"},401);if(Z.startsWith("Bearer "))Z=Z.slice(7);let Q=$?.verify(Z,z);if(!Q)return X.json({message:"Unauthorized",error:"Token could not be decoded"},401);X.set("user",Q)}catch(Z){let Q="Invalid token";if(Z.name==="TokenExpiredError")Q="Token expired";else if(Z.name==="JsonWebTokenError")Q="Malformed or tampered token";return X.json({message:"Unauthorized",error:Q},401)}}}function n($,z,X){if(!$)throw Error("JWT library is not defined, please provide jwt to authenticateJwtDB Function");if(!z)throw Error("User model is not defined, please provide UserModel to authenticateJwtDB Function");return async(Z)=>{try{let Q=Z.cookies?.accessToken??Z.req?.headers?.get("Authorization");if(!Q)return Z.json({message:"Unauthorized",error:"No token provided"},401);if(Q.startsWith("Bearer "))Q=Q.slice(7);let V=$?.verify(Q,X);if(!V)return Z.json({message:"Unauthorized",error:"Token could not be decoded"},401);let G=await z.findById(V._id).select("-password -refreshToken");if(!G)return Z.json({message:"Unauthorized: User not found"},404);Z.set("user",G);return}catch(Q){let V="Invalid token";if(Q.name==="TokenExpiredError")V="Token expired";else if(Q.name==="JsonWebTokenError")V="Malformed or tampered token";return Z.json({message:"Unauthorized",error:V},401)}}}function A($){switch($.split(".").pop()?.toLowerCase()){case"js":return"application/javascript";case"css":return"text/css";case"html":return"text/html";case"json":return"application/json";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"svg":return"image/svg+xml";case"gif":return"image/gif";case"woff":return"font/woff";case"woff2":return"font/woff2";default:return"application/octet-stream"}}var s=["GET","POST","PUT","PATCH","DELETE","ANY","ALL","HEAD","OPTIONS","PROPFIND"],D=Object.freeze({});class I{req;server;path;param;env;executionContext;headers;parsedQuery=null;parsedCookies=null;parsedBody=null;contextData=D;urlObject=null;constructor($,z,X,Z,Q,V){this.req=$,this.server=z,this.path=X,this.param=Z,this.env=Q,this.executionContext=V,this.headers=null}setHeader($,z){if(!this.headers)this.headers=new Headers;return this.headers.set($,z),this}removeHeader($){if(this.headers)this.headers.delete($);return this}set($,z){if(this.contextData===D)this.contextData={};return this.contextData[$]=z,this}get($){if(this.contextData===D)return;return this.contextData[$]}get ip(){if(this.server)return this.server.requestIP(this.req)?.address??null;return this.req.headers.get("CF-Connecting-IP")||null}get url(){if(!this.urlObject)this.urlObject=new URL(this.req.url);return this.urlObject}get query(){if(!this.parsedQuery)this.parsedQuery=this.url.search?Object.fromEntries(this.url.searchParams):D;return this.parsedQuery}get params(){return this.param?this.param:D}get body(){if(this.req.method==="GET")return Promise.resolve(D);if(!this.parsedBody)this.parsedBody=(async()=>{try{let $=await Y$(this.req);if($.error)throw Error($.error);return Object.keys($).length===0?null:$}catch($){throw Error("Invalid request body format")}})();return this.parsedBody}text($,z=200,X){if(!this.headers){if(!X)return new Response($,{status:z,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Z={"Content-Type":"text/plain; charset=utf-8"};return E(X,Z),new Response($,{status:z,headers:Z})}if(X)H(this.headers,X);if(!this.headers?.has("Content-Type"))this.headers?.set("Content-Type","text/plain; charset=utf-8");return new Response($,{status:z,headers:this.headers})}send($,z=200,X){let Z,Q;if($ instanceof Uint8Array||$ instanceof ArrayBuffer)Z="application/octet-stream",Q=$;else if($!==null&&typeof $==="object")Z="application/json; charset=utf-8",Q=JSON.stringify($);else if(typeof $==="string")Z="text/plain; charset=utf-8",Q=$;else Z="text/plain; charset=utf-8",Q=String($);if(!this.headers){if(!X)return new Response(Q,{status:z,headers:{"Content-Type":Z}});let V={"Content-Type":Z};return E(X,V),new Response(Q,{status:z,headers:V})}if(X)H(this.headers,X);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",Z);return new Response(Q,{status:z,headers:this.headers})}json($,z=200,X){if(!this.headers){if(!X)return Response.json($,{status:z,headers:{"Content-Type":"application/json; charset=utf-8"}});let Z={"Content-Type":"application/json; charset=utf-8"};return E(X,Z),Response.json($,{status:z,headers:Z})}if(X)H(this.headers,X);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return new Response(JSON.stringify($),{status:z,headers:this.headers})}file($,z,X=200,Z){let Q=Bun.file($);if(!this.headers){if(!Z)return new Response(Q,{status:X,headers:{"Content-Type":z??A($)}});let V={"Content-Type":z??A($)};return E(Z,V),new Response(Q,{status:X,headers:V})}if(Z)H(this.headers,Z);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",z??A($));return new Response(Q,{status:X,headers:this.headers})}async ejs($,z={},X=200){console.log("this method is diabled now for some time")}redirect($,z=302){if(!this.headers)this.headers=new Headers;return this.headers.set("Location",$),new Response(null,{status:z,headers:this.headers})}setCookie($,z,X={}){if(!this.headers)this.headers=new Headers;let Z=`${encodeURIComponent($)}=${encodeURIComponent(z)}`;if(X.maxAge)Z+=`; Max-Age=${X.maxAge}`;if(X.expires)Z+=`; Expires=${X.expires.toUTCString()}`;if(X.path)Z+=`; Path=${X.path}`;if(X.domain)Z+=`; Domain=${X.domain}`;if(X.secure)Z+="; Secure";if(X.httpOnly)Z+="; HttpOnly";if(X.sameSite)Z+=`; SameSite=${X.sameSite}`;return this.headers.append("Set-Cookie",Z),this}get cookies(){if(!this.parsedCookies){let $=this.req.headers.get("cookie");this.parsedCookies=$?J$($):D}return this.parsedCookies}stream($){let z=new Headers(this.headers??new Headers),X=new ReadableStream({async start(Z){await $(Z),Z.close()}});return new Response(X,{headers:z})}yieldStream($){return new Response}}function H($,z){for(let X in z)$.set(X,z[X])}function E($,z){for(let X in $)z[X]=$[X]}function J$($){return Object.fromEntries($.split(";").map((z)=>{let[X,...Z]=z.trim().split("=");return[X,decodeURIComponent(Z.join("="))]}))}async function Y$($){let z=$.headers.get("Content-Type")||"";if(!z)return{};if($.headers.get("Content-Length")==="0"||!$.body)return{};if(z.startsWith("application/json"))return await $.json();if(z.startsWith("application/x-www-form-urlencoded")){let Z=await $.text();return Object.fromEntries(new URLSearchParams(Z))}if(z.startsWith("multipart/form-data")){let Z=await $.formData(),Q={};for(let[V,G]of Z.entries())Q[V]=G;return Q}return{error:"Unknown request body type"}}var S=($)=>$!==null&&typeof $==="object"&&typeof $.then==="function",x=($)=>$!==null&&typeof $==="object"&&typeof $.status==="number"&&typeof $.headers==="object";async function C($,z,X){if(!z?.length)return;for(let Z=0;Z<z.length;Z++){let Q=z[Z](...X),V=Q instanceof Promise?await Q:Q;if(V&&$!=="onRequest")return V}}async function r($,z,X){for(let Z of $){let Q=await Z(z,X);if(Q)return Q}}async function a($,z,X){let Z=await B$($,z,X),Q=S(Z)?await Z:Z;if(Q)return Q}async function B$($,z,X){if(z.endsWith("/"))z=z.slice(0,-1);if(!$.filters.has(z))if($.filterFunction.length)for(let Z of $.filterFunction){let Q=await Z(X);if(Q)return Q}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function b($,z,X){if($.staticPath){let U=!0;if($.staticRequestPath)U=X.startsWith($.staticRequestPath);if(U){let W=await K$($,X,z);if(W)return W}}let V=($.router.find(z.req.method,"*")?.handler).slice(-1);if(V.length>0){let U=await V[0](z);if(x(U))return U}let G=await Promise.resolve($.routeNotFoundFunc(z));return x(G)?G:y(404,`404 Route not found for ${X}`)}function y($,z){return new Response(JSON.stringify({error:z}),{status:$,headers:{"Content-Type":"application/json"}})}async function K$($,z,X){if(!$.staticPath)return null;let Z=`${$.staticPath}${z}`;if(await Bun.file(Z).exists()){let V=A(Z);return X.file(Z,V,200)}return null}var c=($)=>$.constructor.name==="AsyncFunction",t=($,z,X,...Z)=>{if(z.length>5)$.push(`
4
4
  for (let i = 0; i < diesel.hooks.${X}.length; i++) {
5
5
  const result = diesel.hooks.${X}[i](${Z});
6
6
  const finalResult = result instanceof Promise ? await result : result;
@@ -68,7 +68,7 @@ ${Z}[${$.toUpperCase()}]${B.reset} ${z} - ${Q}${X?.method||""}${B.reset}`);let G
68
68
  ${z.join(`
69
69
  `)}
70
70
  }
71
- `;return Function("runFilter","handleRouteNotFound","generateErrorResponse","Context","isPromise",Q)(a,b,y,M,S)},e=($,z,X,...Z)=>{let Q=[],V;if(typeof Z[0]==="string"||typeof Z[0]==="object")V=Z[0];let G=Z,U=$?.hasOnReqHook?$.hooks.onRequest:[],W=$.filters.has(X),F=$.filterFunction;if(U&&U?.length>0)Q.push(`
71
+ `;return Function("runFilter","handleRouteNotFound","generateErrorResponse","Context","isPromise",Q)(a,b,y,I,S)},e=($,z,X,...Z)=>{let Q=[],V;if(typeof Z[0]==="string"||typeof Z[0]==="object")V=Z[0];let G=Z,U=$?.hasOnReqHook?$.hooks.onRequest:[],W=$.filters.has(X),F=$.filterFunction;if(U&&U?.length>0)Q.push(`
72
72
  const onRequestResult = await runHooks(
73
73
  "onRequest",
74
74
  onRequestHooks,
@@ -108,4 +108,4 @@ ${Z}[${$.toUpperCase()}]${B.reset} ${z} - ${Q}${X?.method||""}${B.reset}`);let G
108
108
  ${Q.join(`
109
109
  `)}
110
110
  }
111
- `;return Function("executeBunMiddlewares","handlers","runHooks","filterFunctions","onRequestHooks","allMiddlewares",Y)(r,G,C,F,U)};var L$=($,z)=>{try{return z($)}catch{return $.replace(/(?:%[0-9A-Fa-f]{2})+/g,(X)=>{try{return z(X)}catch{return X}})}},N$=($)=>L$($,decodeURI),P=($)=>{let z=$.indexOf("/",$.indexOf(":")+4),X=z;for(;X<$.length;X++){let Z=$.charCodeAt(X);if(Z===37){let Q=$.indexOf("?",X),V=$.slice(z,Q===-1?void 0:Q);return N$(V.includes("%25")?V.replace(/%25/g,"%2525"):V)}else if(Z===63)break}return $.slice(z,X)};var h=Symbol.for,O=Symbol("kCapture"),Z$=h("events.errorMonitor"),S$=Symbol("events.maxEventTargetListeners"),C$=Symbol("events.maxEventTargetListenersWarned"),$$=h("nodejs.rejection"),O$=h("nodejs.rejection"),z$=Array.prototype.slice,w=10,N=function($){if(this._events===void 0||this._events===this.__proto__._events)this._events={__proto__:null},this._eventsCount=0;if(this._maxListeners??=void 0,this[O]=$?.captureRejections?Boolean($?.captureRejections):J[O])this.emit=I$},J=N.prototype={};J._events=void 0;J._eventsCount=0;J._maxListeners=void 0;J.setMaxListeners=function($){return d($,"setMaxListeners",0),this._maxListeners=$,this};J.constructor=N;J.getMaxListeners=function(){return this?._maxListeners??w};function Q$($,z){var{_events:X}=$;if(z[0]??=Error("Unhandled error."),!X)throw z[0];var Z=X[Z$];if(Z)for(var Q of z$.call(Z))Q.apply($,z);var V=X.error;if(!V)throw z[0];for(var Q of z$.call(V))Q.apply($,z);return!0}function w$($,z,X,Z){z.then(void 0,function(Q){queueMicrotask(()=>A$($,Q,X,Z))})}function A$($,z,X,Z){if(typeof $[$$]==="function")$[$$](z,X,...Z);else try{$[O]=!1,$.emit("error",z)}finally{$[O]=!0}}var q$=function($,...z){if($==="error")return Q$(this,z);var{_events:X}=this;if(X===void 0)return!1;var Z=X[$];if(Z===void 0)return!1;let Q=Z.length>1?Z.slice():Z;for(let V=0,{length:G}=Q;V<G;V++){let U=Q[V];switch(z.length){case 0:U.call(this);break;case 1:U.call(this,z[0]);break;case 2:U.call(this,z[0],z[1]);break;case 3:U.call(this,z[0],z[1],z[2]);break;default:U.apply(this,z);break}}return!0},I$=function($,...z){if($==="error")return Q$(this,z);var{_events:X}=this;if(X===void 0)return!1;var Z=X[$];if(Z===void 0)return!1;let Q=Z.length>1?Z.slice():Z;for(let V=0,{length:G}=Q;V<G;V++){let U=Q[V],W;switch(z.length){case 0:W=U.call(this);break;case 1:W=U.call(this,z[0]);break;case 2:W=U.call(this,z[0],z[1]);break;case 3:W=U.call(this,z[0],z[1],z[2]);break;default:W=U.apply(this,z);break}if(W!==void 0&&typeof W?.then==="function"&&W.then===Promise.prototype.then)w$(this,W,$,z)}return!0};J.emit=q$;J.addListener=function($,z){_(z);var X=this._events;if(!X)X=this._events={__proto__:null},this._eventsCount=0;else if(X.newListener)this.emit("newListener",$,z.listener??z);var Z=X[$];if(!Z)X[$]=[z],this._eventsCount++;else{Z.push(z);var Q=this._maxListeners??w;if(Q>0&&Z.length>Q&&!Z.warned)V$(this,$,Z)}return this};J.on=J.addListener;J.prependListener=function($,z){_(z);var X=this._events;if(!X)X=this._events={__proto__:null},this._eventsCount=0;else if(X.newListener)this.emit("newListener",$,z.listener??z);var Z=X[$];if(!Z)X[$]=[z],this._eventsCount++;else{Z.unshift(z);var Q=this._maxListeners??w;if(Q>0&&Z.length>Q&&!Z.warned)V$(this,$,Z)}return this};function V$($,z,X){X.warned=!0;let Z=Error(`Possible EventEmitter memory leak detected. ${X.length} ${String(z)} listeners added to [${$.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);Z.name="MaxListenersExceededWarning",Z.emitter=$,Z.type=z,Z.count=X.length,console.warn(Z)}function G$($,z,...X){this.removeListener($,z),z.apply(this,X)}J.once=function($,z){_(z);let X=G$.bind(this,$,z);return X.listener=z,this.addListener($,X),this};J.prependOnceListener=function($,z){_(z);let X=G$.bind(this,$,z);return X.listener=z,this.prependListener($,X),this};J.removeListener=function($,z){_(z);var{_events:X}=this;if(!X)return this;var Z=X[$];if(!Z)return this;var Q=Z.length;let V=-1;for(let G=Q-1;G>=0;G--)if(Z[G]===z||Z[G].listener===z){V=G;break}if(V<0)return this;if(V===0)Z.shift();else Z.splice(V,1);if(Z.length===0)delete X[$],this._eventsCount--;return this};J.off=J.removeListener;J.removeAllListeners=function($){var{_events:z}=this;if($&&z){if(z[$])delete z[$],this._eventsCount--}else this._events={__proto__:null};return this};J.listeners=function($){var{_events:z}=this;if(!z)return[];var X=z[$];if(!X)return[];return X.map((Z)=>Z.listener??Z)};J.rawListeners=function($){var{_events:z}=this;if(!z)return[];var X=z[$];if(!X)return[];return X.slice()};J.listenerCount=function($){var{_events:z}=this;if(!z)return 0;return z[$]?.length??0};J.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};J[O]=!1;function M$($,z,X){var Z=X?.signal;if(U$(Z,"options.signal"),Z?.aborted)throw new m(void 0,{cause:Z?.reason});let{resolve:Q,reject:V,promise:G}=$newPromiseCapability(Promise),U=(Y)=>{if($.removeListener(z,W),Z!=null)f(Z,"abort",F);V(Y)},W=(...Y)=>{if(typeof $.removeListener==="function")$.removeListener("error",U);if(Z!=null)f(Z,"abort",F);Q(Y)};if(X$($,z,W,{once:!0}),z!=="error"&&typeof $.once==="function")$.once("error",U);function F(){f($,z,W),f($,"error",U),V(new m(void 0,{cause:Z?.reason}))}if(Z!=null)X$(Z,"abort",F,{once:!0});return G}function _$($,z){return $.listeners(z)}function j$($,...z){d($,"setMaxListeners",0);var X;if(z&&(X=z.length))for(let Z=0;Z<X;Z++)z[Z].setMaxListeners($);else w=$}function R$($,z){return $.listenerCount(z)}function f($,z,X,Z){if(typeof $.removeListener==="function")$.removeListener(z,X);else $.removeEventListener(z,X,Z)}function X$($,z,X,Z){if(typeof $.on==="function")if(Z.once)$.once(z,X);else $.on(z,X);else $.addEventListener(z,X,Z)}class m extends Error{constructor($="The operation was aborted",z=void 0){if(z!==void 0&&typeof z!=="object")throw q("options","Object",z);super($,z);this.code="ABORT_ERR",this.name="AbortError"}}function q($,z,X){let Z=TypeError(`The "${$}" argument must be of type ${z}. Received ${X}`);return Z.code="ERR_INVALID_ARG_TYPE",Z}function T$($,z,X){let Z=RangeError(`The "${$}" argument is out of range. It must be ${z}. Received ${X}`);return Z.code="ERR_OUT_OF_RANGE",Z}function U$($,z){if($!==void 0&&($===null||typeof $!=="object"||!("aborted"in $)))throw q(z,"AbortSignal",$)}function d($,z,X,Z){if(typeof $!=="number")throw q(z,"number",$);if(X!=null&&$<X||Z!=null&&$>Z||(X!=null||Z!=null)&&Number.isNaN($))throw T$(z,`${X!=null?`>= ${X}`:""}${X!=null&&Z!=null?" && ":""}${Z!=null?`<= ${Z}`:""}`,$)}function _($){if(typeof $!=="function")throw TypeError("The listener must be a function")}function H$($,z){if(typeof $!=="boolean")throw q(z,"boolean",$)}function E$($){return $?._maxListeners??w}function b$($,z){if($===void 0)throw q("signal","AbortSignal",$);if(U$($,"signal"),typeof z!=="function")throw q("listener","function",z);let X;if($.aborted)queueMicrotask(()=>z());else $.addEventListener("abort",z,{__proto__:null,once:!0}),X=()=>{$.removeEventListener("abort",z)};return{__proto__:null,[Symbol.dispose](){X?.()}}}Object.defineProperties(N,{captureRejections:{get(){return J[O]},set($){H$($,"EventEmitter.captureRejections"),J[O]=$},enumerable:!0},defaultMaxListeners:{enumerable:!0,get:()=>{return w},set:($)=>{d($,"defaultMaxListeners",0),w=$}},kMaxEventTargetListeners:{value:S$,enumerable:!1,configurable:!1,writable:!1},kMaxEventTargetListenersWarned:{value:C$,enumerable:!1,configurable:!1,writable:!1}});Object.assign(N,{once:M$,getEventListeners:_$,getMaxListeners:E$,setMaxListeners:j$,EventEmitter:N,usingDomains:!1,captureRejectionSymbol:O$,errorMonitor:Z$,addAbortListener:b$,init:N,listenerCount:R$});class k{children;handlers;middlewares;params;paramName;constructor(){this.children={},this.handlers={},this.middlewares=[],this.params={},this.paramName=""}}class j{root;globalMiddlewares;constructor(){this.root=new k,this.globalMiddlewares=[]}pushMiddleware($,z){if(!Array.isArray(z))z=[z];if($==="/"){this.globalMiddlewares.push(...z);return}let X=this.root,Z=$.split("/").filter(Boolean);for(let Q of Z){let V=Q;if(Q.startsWith(":"))V=":";else if(Q.startsWith("*"))X.middlewares.push(...z);if(!X.children[V])X.children[V]=new k;X=X.children[V]}X.middlewares.push(...z)}addMiddleware($,z){return this.pushMiddleware($,z)}insert($,z,X){let Z=this.root;if(z==="/"){Z.handlers[$]=X,Z.params=D;return}let Q=z.split("/").filter(Boolean),V={};for(let G=0;G<Q.length;G++){let U=Q[G],W=U,F="";if(U.startsWith(":"))W=":",F=U.slice(1);if(!Z.children[W])Z.children[W]=new k;if(Z=Z.children[W],F)V[F]=G,Z.paramName=F}Z.params=V,Z.handlers[$]=X}add($,z,X){return this.insert($,z,X)}search($,z){let X=this.root,Z=z.split("/"),Q=this.globalMiddlewares.slice(),V;for(let G=0;G<Z.length;G++){let U=Z[G];if(U.length===0)continue;if(X.children[U])X=X.children[U];else if(X.children[":"]){if(X=X.children[":"],!V)V={};V[X.paramName]=U}else if(X.children["*"]){X=X.children["*"];break}else return{params:V,handler:Q};if(X.middlewares.length>0){let W=X.middlewares;for(let F=0;F<W.length;F++)Q.push(W[F])}}if(X.handlers[$])Q.push(X.handlers[$]);if(X.handlers.ALL)Q.push(X.handlers.ALL);return{params:V,handler:Q}}find($,z){return this.search($,z)}}class o{static create($){switch($){case"t2":return new j;case"trie":return new j;default:return new j}}}class I{static instance;routes;tempRoutes;tempMiddlewares=new Map;router;hasOnReqHook;hasPreHandlerHook;hasPostHandlerHook;hasOnSendHook;hasOnError;hooks;corsConfig;FilterRoutes;filters;filterFunction;hasFilterEnabled;serverInstance;staticFiles;user_jwt_secret;baseApiUrl;enableFileRouter;idleTimeOut;routeNotFoundFunc;prefixApiUrl;compileConfig;#$=!1;emitter;errorFormat;platform="bun";staticPath;staticRequestPath=void 0;get;post;put;patch;delete;any;head;options;propfind;all;constructor($={}){s.forEach((K)=>{this[K.toLocaleLowerCase()]=(T,...W$)=>{return this.addRoute(K,T,W$),this}});let{router:z="t2",routerInstance:X,errorFormat:Z="json",platform:Q="bun",enableFileRouting:V=!1,prefixApiUrl:G="",baseApiUrl:U="",jwtSecret:W,idleTimeOut:F=10,pipelineArchitecture:Y=!1,logger:R,onError:L}=$;if(X)this.router=X;else this.router=o.create(z);if(this.errorFormat=Z,this.platform=Q,!I.instance)I.instance=this;if(Y)this.#$=!0;if(this.errorFormat=Z,this.emitter=new N,this.prefixApiUrl=G??"",this.fetch=this.fetch.bind(this),this.routes={},this.idleTimeOut=F??10,this.enableFileRouter=V??!1,this.baseApiUrl=U||"",this.user_jwt_secret=W||process.env.DIESEL_JWT_SECRET||"default_diesel_secret_for_jwt",this.tempRoutes=new Map,this.corsConfig=null,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hasOnError=!1,this.hooks={onRequest:[],preHandler:[],postHandler:[],onSend:[],onError:[],onClose:[]},L)this.addHooks("onError",(K,T)=>{console.log("Got an exception:",K),console.log("Request Path:",T)});if(R)this.useLogger({app:this});this.FilterRoutes=[],this.filters=new Set,this.filterFunction=[],this.hasFilterEnabled=!1,this.serverInstance=null,this.staticPath=null,this.staticFiles={},this.routeNotFoundFunc=()=>{},this.compileConfig=null}static router($){if(!this.instance)this.instance=new I;return new Proxy(this.instance,{get(z,X,Z){return(Q,V)=>{let G=V,U="";if(typeof Q==="string")U=Q;else if(typeof Q==="function")G=Q;else if(typeof Q!=="string")U="";let W=$+U;return z[X](W,G)}}})}setupFilter(){return this.hasFilterEnabled=!0,{publicRoutes:(...$)=>{return this.FilterRoutes=$,this.setupFilter()},permitAll:()=>{for(let $ of this?.FilterRoutes){if($.endsWith("/"))$=$.slice(0,-1);this.filters.add($)}return this.setupFilter()},authenticate:($)=>{if($?.length){let z=async(X,Z)=>{let Q=X.path;for(let V of this.filters)if(Q.startsWith(V))return;for(let V of $){let G=await V(X,Z);if(G)return G}};this.router.addMiddleware("/",[z])}},authenticateJwt:($)=>{let z=async(X)=>{let Z=X.path;for(let V of this.filters)if(Z.startsWith(V))return;let Q=l($,this.user_jwt_secret)(X);if(Q)return Q};this.router.addMiddleware("/",z)},authenticateJwtDB:($,z)=>{let X=async(Z)=>{let Q=Z.path;for(let G of this.filters)if(Q.startsWith(G))return;let V=n($,z,this.user_jwt_secret)(Z);if(V)return V};this.router.addMiddleware("/",X)}}}redirect($,z,X){return this.any($,(Z)=>{let Q=Z.params,V=z;if(Q)for(let U in Q)V=V.replace(`:${U}`,Q[U]);let G=Z.url.search;if(G)V+=G;return Z.redirect(V,X)}),this}static($,z){return this.staticPath=$,this.staticRequestPath=z,this}staticHtml($){return this.staticFiles={...this.staticFiles,...$},this}addHooks($,z){if(typeof $!=="string")throw Error("hookName must be a string");if(typeof z!=="function")throw Error("callback must be a instance of function");switch($){case"onRequest":this.hooks.onRequest?.push(z),this.hasOnReqHook=!0;break;case"preHandler":this.hooks.preHandler?.push(z),this.hasPreHandlerHook=!0;break;case"postHandler":this.hooks.postHandler?.push(z),this.hasPostHandlerHook=!0;break;case"onSend":this.hooks.onSend?.push(z),this.hasOnSendHook=!0;break;case"onError":this.hooks.onError?.push(z),this.hasOnError=!0;break;case"onClose":this.hooks.onClose?.push(z);break;default:throw Error(`Unknown hook type: ${$}`)}return this}useLogger($){return i($),this}useAdvancedLogger($){return p($),this}BunRoute($,z,...X){if(!z||typeof z!=="string")throw Error("give a path in string format");let Z=e(this,$.toUpperCase(),z,...X);return this.routes[z]=Z,this}listen($,...z){let X="0.0.0.0",Z=void 0,Q={};for(let G of z)if(typeof G==="string")X=G;else if(typeof G==="function")Z=G;else if(typeof G==="object"&&G!==null)Q=G;let V={port:$,hostname:X,idleTimeOut:this.idleTimeOut,fetch:this.fetch(),static:this.staticFiles};if(this.routes&&Object.keys(this.routes).length>0)V.routes=this.routes;if(Q.cert&&Q.key)V.certFile=Q.cert,V.keyFile=Q.key;return this.serverInstance=Bun?.serve(V),Z&&Z(),this.serverInstance}close($){if(this.serverInstance)this.serverInstance.stop(!0),this.serverInstance=null,$?$():console.log("Server has been stopped");else console.warn("Server is not running.")}cfFetch(){return this.tempRoutes=null,this.tempMiddlewares=null,($,z,X)=>{return this.#z($,void 0,z,X)}}fetch(){if(this.tempRoutes=null,this.tempMiddlewares=null,this.platform==="cf"||this.platform==="cloudflare"){if(this.#$){let $=u(this);return(z,X,Z)=>{return $(z,this,void 0,X,Z).catch(async(Q)=>{return this.handleError(Q,P(z.url),z)})}}return($,z,X)=>{return this.#z($,void 0,z,X)}}if(this.#$){let $=u(this);return(z,X)=>{return $(z,this,X,void 0,void 0).catch(async(Z)=>{return this.handleError(Z,P(z.url),z)})}}return this.#z.bind(this)}async#z($,z,X,Z){let Q=P($.url),V=this.router.find($.method,Q),G=new M($,z,Q,V?.params||D,X,Z);try{if(this.hasOnReqHook)await C("onRequest",this.hooks.onRequest,[G]);if(this.hasPreHandlerHook){let F=await C("preHandler",this.hooks.preHandler,[G]);if(F)return F}let U,W=V?.handler;if(W.length===1){let F=W[0](G);U=S(F)?await F:F}else for(let F=0;F<W.length;F++){let Y=W[F](G);if(U=S(Y)?await Y:Y,U)break}if(this.hasOnSendHook){let F=await C("onSend",this.hooks.onSend,[G,U]);if(F)return F}if(U)return U;return await b(this,G,Q)}catch(U){return this.handleError(U,Q,$)}}async handleError($,z,X){let Q=this.errorFormat,V=await C("onError",this.hooks.onError,[$,z,X]);if(V)return V;if($&&typeof $==="object"&&$.name==="HTTPException"){let W=$;if(console.error(`HTTPException on path: ${z}`,{status:W.status,message:W.message,cause:W.cause,res:W.res,stack:W.stack}),W.res)return W.res;return Q==="json"?Response.json({error:W.message},{status:W.status}):new Response(W.message,{status:W.status})}let G=$ instanceof Error?$.message:"Internal Server Error",U=$ instanceof Error?$.stack:void 0;if(console.error(`Error on path: ${z}`,{message:G,stack:U}),Q==="json"){let W={error:G,...!1,path:z};return Response.json(W,{status:500,headers:{"Content-Type":"application/json"}})}else{let W=`Error: ${G}`;return new Response(W,{headers:{"Content-Type":"text/plain"},status:500})}}mount($,z){let X=$.endsWith("/*")?$.slice(0,-1):$,Z=X==="/"?0:X.length;this.any($,(Q)=>{let V=new URL(Q.req.url);V.pathname=V.pathname.slice(Z)||"/";let G=new Request(V,Q.req);return z(G,Q.server,Q.env,Q.executionContext)})}route($,z){$=$&&$.length>0?$:z?.prefixApiUrl;let X=z?.tempRoutes??new Map;for(let[Z,Q]of X.entries()){let V=Z.replace(/::\w+$/,""),G=`${$}${V}`,U=Q.handlers.slice(0,-1);this.router.addMiddleware(G,U);let W=Q.handlers[Q.handlers.length-1],F=Q.method;try{this.router.add(F,G,W)}catch(Y){console.error(`Error inserting ${G}:`,Y)}}for(let[Z,Q]of z?.tempMiddlewares?.entries()){let V=Z==="/"?$||"/":`${$}${Z}`;this.router.addMiddleware(V,Q)}return z=null,this}register($){let z=new I,X=()=>{};return this}sub($,z){let X=z.fetch();return this.mount($,X)}addMiddlewareInRouter($,z){this.router.addMiddleware($,z)}addRoute($,z,X){if(typeof z!=="string")throw Error(`Error in ${X[X.length-1]}: Path must be a string. Received: ${typeof z}`);if(typeof $!=="string")throw Error(`Error in addRoute: Method must be a string. Received: ${typeof $}`);this.tempRoutes?.set(z+"::"+$,{method:$,handlers:X});let Z=X.slice(0,-1),Q=X[X.length-1];if(Z.length>0)this.addMiddlewareInRouter(z,Z);try{if($==="ANY"){let V=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD","PROPFIND"];for(let G of V)try{this.router.add(G,z,Q)}catch(U){}}else this.router.add($,z,Q)}catch(V){console.error(`Error inserting ${z}:`,V)}}use($,...z){if(typeof $==="string"){let X=$==="/"?"/":$;if(!this.tempMiddlewares?.has(X))this.tempMiddlewares?.set(X,[]);this.tempMiddlewares?.get(X).push(...z),this.router.addMiddleware(X,z)}else if(typeof $==="function"){let X=[$,...z];if(!this.tempMiddlewares?.has("/"))this.tempMiddlewares?.set("/",[]);this.tempMiddlewares?.get("/").push(...z),this.router.addMiddleware("/",X)}return this}routeNotFound($){return this.routeNotFoundFunc=$,this}onMethod($,z,...X){let Z=Array.isArray($)?$:[$];for(let Q of Z){let V=Q.toLowerCase();if(V in this)this[V](z,...X);else this.addRoute(Q.toUpperCase(),z,X)}return this}on($,z){return this.emitter.on($,z),this}emit($,...z){return this.emitter.emit($,...z),this}}export{I as default};
111
+ `;return Function("executeBunMiddlewares","handlers","runHooks","filterFunctions","onRequestHooks","allMiddlewares",Y)(r,G,C,F,U)};var L$=($,z)=>{try{return z($)}catch{return $.replace(/(?:%[0-9A-Fa-f]{2})+/g,(X)=>{try{return z(X)}catch{return X}})}},N$=($)=>L$($,decodeURI),P=($)=>{let z=$.indexOf("/",$.indexOf(":")+4),X=z;for(;X<$.length;X++){let Z=$.charCodeAt(X);if(Z===37){let Q=$.indexOf("?",X),V=$.slice(z,Q===-1?void 0:Q);return N$(V.includes("%25")?V.replace(/%25/g,"%2525"):V)}else if(Z===63)break}return $.slice(z,X)};var h=Symbol.for,O=Symbol("kCapture"),Z$=h("events.errorMonitor"),S$=Symbol("events.maxEventTargetListeners"),C$=Symbol("events.maxEventTargetListenersWarned"),$$=h("nodejs.rejection"),O$=h("nodejs.rejection"),z$=Array.prototype.slice,w=10,N=function($){if(this._events===void 0||this._events===this.__proto__._events)this._events={__proto__:null},this._eventsCount=0;if(this._maxListeners??=void 0,this[O]=$?.captureRejections?Boolean($?.captureRejections):J[O])this.emit=M$},J=N.prototype={};J._events=void 0;J._eventsCount=0;J._maxListeners=void 0;J.setMaxListeners=function($){return d($,"setMaxListeners",0),this._maxListeners=$,this};J.constructor=N;J.getMaxListeners=function(){return this?._maxListeners??w};function Q$($,z){var{_events:X}=$;if(z[0]??=Error("Unhandled error."),!X)throw z[0];var Z=X[Z$];if(Z)for(var Q of z$.call(Z))Q.apply($,z);var V=X.error;if(!V)throw z[0];for(var Q of z$.call(V))Q.apply($,z);return!0}function w$($,z,X,Z){z.then(void 0,function(Q){queueMicrotask(()=>A$($,Q,X,Z))})}function A$($,z,X,Z){if(typeof $[$$]==="function")$[$$](z,X,...Z);else try{$[O]=!1,$.emit("error",z)}finally{$[O]=!0}}var q$=function($,...z){if($==="error")return Q$(this,z);var{_events:X}=this;if(X===void 0)return!1;var Z=X[$];if(Z===void 0)return!1;let Q=Z.length>1?Z.slice():Z;for(let V=0,{length:G}=Q;V<G;V++){let U=Q[V];switch(z.length){case 0:U.call(this);break;case 1:U.call(this,z[0]);break;case 2:U.call(this,z[0],z[1]);break;case 3:U.call(this,z[0],z[1],z[2]);break;default:U.apply(this,z);break}}return!0},M$=function($,...z){if($==="error")return Q$(this,z);var{_events:X}=this;if(X===void 0)return!1;var Z=X[$];if(Z===void 0)return!1;let Q=Z.length>1?Z.slice():Z;for(let V=0,{length:G}=Q;V<G;V++){let U=Q[V],W;switch(z.length){case 0:W=U.call(this);break;case 1:W=U.call(this,z[0]);break;case 2:W=U.call(this,z[0],z[1]);break;case 3:W=U.call(this,z[0],z[1],z[2]);break;default:W=U.apply(this,z);break}if(W!==void 0&&typeof W?.then==="function"&&W.then===Promise.prototype.then)w$(this,W,$,z)}return!0};J.emit=q$;J.addListener=function($,z){_(z);var X=this._events;if(!X)X=this._events={__proto__:null},this._eventsCount=0;else if(X.newListener)this.emit("newListener",$,z.listener??z);var Z=X[$];if(!Z)X[$]=[z],this._eventsCount++;else{Z.push(z);var Q=this._maxListeners??w;if(Q>0&&Z.length>Q&&!Z.warned)V$(this,$,Z)}return this};J.on=J.addListener;J.prependListener=function($,z){_(z);var X=this._events;if(!X)X=this._events={__proto__:null},this._eventsCount=0;else if(X.newListener)this.emit("newListener",$,z.listener??z);var Z=X[$];if(!Z)X[$]=[z],this._eventsCount++;else{Z.unshift(z);var Q=this._maxListeners??w;if(Q>0&&Z.length>Q&&!Z.warned)V$(this,$,Z)}return this};function V$($,z,X){X.warned=!0;let Z=Error(`Possible EventEmitter memory leak detected. ${X.length} ${String(z)} listeners added to [${$.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);Z.name="MaxListenersExceededWarning",Z.emitter=$,Z.type=z,Z.count=X.length,console.warn(Z)}function G$($,z,...X){this.removeListener($,z),z.apply(this,X)}J.once=function($,z){_(z);let X=G$.bind(this,$,z);return X.listener=z,this.addListener($,X),this};J.prependOnceListener=function($,z){_(z);let X=G$.bind(this,$,z);return X.listener=z,this.prependListener($,X),this};J.removeListener=function($,z){_(z);var{_events:X}=this;if(!X)return this;var Z=X[$];if(!Z)return this;var Q=Z.length;let V=-1;for(let G=Q-1;G>=0;G--)if(Z[G]===z||Z[G].listener===z){V=G;break}if(V<0)return this;if(V===0)Z.shift();else Z.splice(V,1);if(Z.length===0)delete X[$],this._eventsCount--;return this};J.off=J.removeListener;J.removeAllListeners=function($){var{_events:z}=this;if($&&z){if(z[$])delete z[$],this._eventsCount--}else this._events={__proto__:null};return this};J.listeners=function($){var{_events:z}=this;if(!z)return[];var X=z[$];if(!X)return[];return X.map((Z)=>Z.listener??Z)};J.rawListeners=function($){var{_events:z}=this;if(!z)return[];var X=z[$];if(!X)return[];return X.slice()};J.listenerCount=function($){var{_events:z}=this;if(!z)return 0;return z[$]?.length??0};J.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};J[O]=!1;function I$($,z,X){var Z=X?.signal;if(U$(Z,"options.signal"),Z?.aborted)throw new m(void 0,{cause:Z?.reason});let{resolve:Q,reject:V,promise:G}=$newPromiseCapability(Promise),U=(Y)=>{if($.removeListener(z,W),Z!=null)f(Z,"abort",F);V(Y)},W=(...Y)=>{if(typeof $.removeListener==="function")$.removeListener("error",U);if(Z!=null)f(Z,"abort",F);Q(Y)};if(X$($,z,W,{once:!0}),z!=="error"&&typeof $.once==="function")$.once("error",U);function F(){f($,z,W),f($,"error",U),V(new m(void 0,{cause:Z?.reason}))}if(Z!=null)X$(Z,"abort",F,{once:!0});return G}function _$($,z){return $.listeners(z)}function j$($,...z){d($,"setMaxListeners",0);var X;if(z&&(X=z.length))for(let Z=0;Z<X;Z++)z[Z].setMaxListeners($);else w=$}function R$($,z){return $.listenerCount(z)}function f($,z,X,Z){if(typeof $.removeListener==="function")$.removeListener(z,X);else $.removeEventListener(z,X,Z)}function X$($,z,X,Z){if(typeof $.on==="function")if(Z.once)$.once(z,X);else $.on(z,X);else $.addEventListener(z,X,Z)}class m extends Error{constructor($="The operation was aborted",z=void 0){if(z!==void 0&&typeof z!=="object")throw q("options","Object",z);super($,z);this.code="ABORT_ERR",this.name="AbortError"}}function q($,z,X){let Z=TypeError(`The "${$}" argument must be of type ${z}. Received ${X}`);return Z.code="ERR_INVALID_ARG_TYPE",Z}function T$($,z,X){let Z=RangeError(`The "${$}" argument is out of range. It must be ${z}. Received ${X}`);return Z.code="ERR_OUT_OF_RANGE",Z}function U$($,z){if($!==void 0&&($===null||typeof $!=="object"||!("aborted"in $)))throw q(z,"AbortSignal",$)}function d($,z,X,Z){if(typeof $!=="number")throw q(z,"number",$);if(X!=null&&$<X||Z!=null&&$>Z||(X!=null||Z!=null)&&Number.isNaN($))throw T$(z,`${X!=null?`>= ${X}`:""}${X!=null&&Z!=null?" && ":""}${Z!=null?`<= ${Z}`:""}`,$)}function _($){if(typeof $!=="function")throw TypeError("The listener must be a function")}function H$($,z){if(typeof $!=="boolean")throw q(z,"boolean",$)}function E$($){return $?._maxListeners??w}function b$($,z){if($===void 0)throw q("signal","AbortSignal",$);if(U$($,"signal"),typeof z!=="function")throw q("listener","function",z);let X;if($.aborted)queueMicrotask(()=>z());else $.addEventListener("abort",z,{__proto__:null,once:!0}),X=()=>{$.removeEventListener("abort",z)};return{__proto__:null,[Symbol.dispose](){X?.()}}}Object.defineProperties(N,{captureRejections:{get(){return J[O]},set($){H$($,"EventEmitter.captureRejections"),J[O]=$},enumerable:!0},defaultMaxListeners:{enumerable:!0,get:()=>{return w},set:($)=>{d($,"defaultMaxListeners",0),w=$}},kMaxEventTargetListeners:{value:S$,enumerable:!1,configurable:!1,writable:!1},kMaxEventTargetListenersWarned:{value:C$,enumerable:!1,configurable:!1,writable:!1}});Object.assign(N,{once:I$,getEventListeners:_$,getMaxListeners:E$,setMaxListeners:j$,EventEmitter:N,usingDomains:!1,captureRejectionSymbol:O$,errorMonitor:Z$,addAbortListener:b$,init:N,listenerCount:R$});class k{children;handlers;middlewares;params;paramName;constructor(){this.children={},this.handlers={},this.middlewares=[],this.params={},this.paramName=""}}class j{root;globalMiddlewares;constructor(){this.root=new k,this.globalMiddlewares=[]}pushMiddleware($,z){if(!Array.isArray(z))z=[z];if($==="/"){this.globalMiddlewares.push(...z);return}let X=this.root,Z=$.split("/").filter(Boolean);for(let Q of Z){let V=Q;if(Q.startsWith(":"))V=":";else if(Q.startsWith("*"))X.middlewares.push(...z);if(!X.children[V])X.children[V]=new k;X=X.children[V]}X.middlewares.push(...z)}addMiddleware($,z){return this.pushMiddleware($,z)}insert($,z,X){let Z=this.root;if(z==="/"){Z.handlers[$]=X,Z.params=D;return}let Q=z.split("/").filter(Boolean),V={};for(let G=0;G<Q.length;G++){let U=Q[G],W=U,F="";if(U.startsWith(":"))W=":",F=U.slice(1);if(!Z.children[W])Z.children[W]=new k;if(Z=Z.children[W],F)V[F]=G,Z.paramName=F}Z.params=V,Z.handlers[$]=X}add($,z,X){return this.insert($,z,X)}search($,z){let X=this.root,Z=z.split("/"),Q=this.globalMiddlewares.slice(),V;for(let G=0;G<Z.length;G++){let U=Z[G];if(U.length===0)continue;if(X.children[U])X=X.children[U];else if(X.children[":"]){if(X=X.children[":"],!V)V={};V[X.paramName]=U}else if(X.children["*"]){X=X.children["*"];break}else return{params:V,handler:Q};if(X.middlewares.length>0){let W=X.middlewares;for(let F=0;F<W.length;F++)Q.push(W[F])}}if(X.handlers[$])Q.push(X.handlers[$]);if(X.handlers.ALL)Q.push(X.handlers.ALL);return{params:V,handler:Q}}find($,z){return this.search($,z)}}class o{static create($){switch($){case"t2":return new j;case"trie":return new j;default:return new j}}}class M{static instance;routes;tempRoutes;tempMiddlewares=new Map;router;hasOnReqHook;hasPreHandlerHook;hasPostHandlerHook;hasOnSendHook;hasOnError;hooks;corsConfig;FilterRoutes;filters;filterFunction;hasFilterEnabled;serverInstance;staticFiles;user_jwt_secret;baseApiUrl;enableFileRouter;idleTimeOut;routeNotFoundFunc;prefixApiUrl;compileConfig;#$=!1;emitter;errorFormat;platform="bun";staticPath;staticRequestPath=void 0;get;post;put;patch;delete;any;head;options;propfind;all;constructor($={}){s.forEach((K)=>{this[K.toLocaleLowerCase()]=(T,...W$)=>{return this.addRoute(K,T,W$),this}});let{router:z="t2",routerInstance:X,errorFormat:Z="json",platform:Q="bun",enableFileRouting:V=!1,prefixApiUrl:G="",baseApiUrl:U="",jwtSecret:W,idleTimeOut:F=10,pipelineArchitecture:Y=!1,logger:R,onError:L}=$;if(X)this.router=X;else this.router=o.create(z);if(this.errorFormat=Z,this.platform=Q,!M.instance)M.instance=this;if(Y)this.#$=!0;if(this.errorFormat=Z,this.emitter=new N,this.prefixApiUrl=G??"",this.fetch=this.fetch.bind(this),this.routes={},this.idleTimeOut=F??10,this.enableFileRouter=V??!1,this.baseApiUrl=U||"",this.user_jwt_secret=W||process.env.DIESEL_JWT_SECRET||"default_diesel_secret_for_jwt",this.tempRoutes=new Map,this.corsConfig=null,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hasOnError=!1,this.hooks={onRequest:[],preHandler:[],postHandler:[],onSend:[],onError:[],onClose:[]},L)this.addHooks("onError",(K,T)=>{console.log("Got an exception:",K),console.log("Request Path:",T)});if(R)this.useLogger({app:this});this.FilterRoutes=[],this.filters=new Set,this.filterFunction=[],this.hasFilterEnabled=!1,this.serverInstance=null,this.staticPath=null,this.staticFiles={},this.routeNotFoundFunc=()=>{},this.compileConfig=null}static router($){if(!this.instance)this.instance=new M;return new Proxy(this.instance,{get(z,X,Z){return(Q,V)=>{let G=V,U="";if(typeof Q==="string")U=Q;else if(typeof Q==="function")G=Q;else if(typeof Q!=="string")U="";let W=$+U;return z[X](W,G)}}})}setupFilter(){return this.hasFilterEnabled=!0,{publicRoutes:(...$)=>{return this.FilterRoutes=$,this.setupFilter()},permitAll:()=>{for(let $ of this?.FilterRoutes){if($.endsWith("/"))$=$.slice(0,-1);this.filters.add($)}return this.setupFilter()},authenticate:($)=>{if($?.length){let z=async(X,Z)=>{let Q=X.path;for(let V of this.filters)if(Q.startsWith(V))return;for(let V of $){let G=await V(X,Z);if(G)return G}};this.router.addMiddleware("/",[z])}},authenticateJwt:($)=>{let z=async(X)=>{let Z=X.path;for(let V of this.filters)if(Z.startsWith(V))return;let Q=l($,this.user_jwt_secret)(X);if(Q)return Q};this.router.addMiddleware("/",z)},authenticateJwtDB:($,z)=>{let X=async(Z)=>{let Q=Z.path;for(let G of this.filters)if(Q.startsWith(G))return;let V=n($,z,this.user_jwt_secret)(Z);if(V)return V};this.router.addMiddleware("/",X)}}}redirect($,z,X){return this.any($,(Z)=>{let Q=Z.params,V=z;if(Q)for(let U in Q)V=V.replace(`:${U}`,Q[U]);let G=Z.url.search;if(G)V+=G;return Z.redirect(V,X)}),this}static($,z){return this.staticPath=$,this.staticRequestPath=z,this}staticHtml($){return this.staticFiles={...this.staticFiles,...$},this}addHooks($,z){if(typeof $!=="string")throw Error("hookName must be a string");if(typeof z!=="function")throw Error("callback must be a instance of function");switch($){case"onRequest":this.hooks.onRequest?.push(z),this.hasOnReqHook=!0;break;case"preHandler":this.hooks.preHandler?.push(z),this.hasPreHandlerHook=!0;break;case"postHandler":this.hooks.postHandler?.push(z),this.hasPostHandlerHook=!0;break;case"onSend":this.hooks.onSend?.push(z),this.hasOnSendHook=!0;break;case"onError":this.hooks.onError?.push(z),this.hasOnError=!0;break;case"onClose":this.hooks.onClose?.push(z);break;default:throw Error(`Unknown hook type: ${$}`)}return this}useLogger($){return i($),this}useAdvancedLogger($){return p($),this}BunRoute($,z,...X){if(!z||typeof z!=="string")throw Error("give a path in string format");let Z=e(this,$.toUpperCase(),z,...X);return this.routes[z]=Z,this}listen($,...z){let X="0.0.0.0",Z=void 0,Q={};for(let G of z)if(typeof G==="string")X=G;else if(typeof G==="function")Z=G;else if(typeof G==="object"&&G!==null)Q=G;let V={port:$,hostname:X,idleTimeOut:this.idleTimeOut,fetch:this.fetch(),static:this.staticFiles};if(this.routes&&Object.keys(this.routes).length>0)V.routes=this.routes;if(Q.cert&&Q.key)V.certFile=Q.cert,V.keyFile=Q.key;return this.serverInstance=Bun?.serve(V),Z&&Z(),this.serverInstance}close($){if(this.serverInstance)this.serverInstance.stop(!0),this.serverInstance=null,$?$():console.log("Server has been stopped");else console.warn("Server is not running.")}cfFetch(){return this.tempRoutes=null,this.tempMiddlewares=null,($,z,X)=>{return this.#z($,void 0,z,X)}}fetch(){if(this.tempRoutes=null,this.tempMiddlewares=null,this.platform==="cf"||this.platform==="cloudflare"){if(this.#$){let $=u(this);return(z,X,Z)=>{return $(z,this,void 0,X,Z).catch(async(Q)=>{return this.handleError(Q,P(z.url),z)})}}return($,z,X)=>{return this.#z($,void 0,z,X)}}if(this.#$){let $=u(this);return(z,X)=>{return $(z,this,X,void 0,void 0).catch(async(Z)=>{return this.handleError(Z,P(z.url),z)})}}return this.#z.bind(this)}async#z($,z,X,Z){let Q=P($.url),V=this.router.find($.method,Q),G=new I($,z,Q,V?.params||D,X,Z);try{if(this.hasOnReqHook)await C("onRequest",this.hooks.onRequest,[G]);if(this.hasPreHandlerHook){let F=await C("preHandler",this.hooks.preHandler,[G]);if(F)return F}let U,W=V?.handler;if(W.length===1){let F=W[0](G);U=S(F)?await F:F}else for(let F=0;F<W.length;F++){let Y=W[F](G);if(U=S(Y)?await Y:Y,U)break}if(this.hasOnSendHook){let F=await C("onSend",this.hooks.onSend,[G,U]);if(F)return F}if(U)return U;return await b(this,G,Q)}catch(U){return this.handleError(U,Q,$)}}async handleError($,z,X){let Q=this.errorFormat,V=await C("onError",this.hooks.onError,[$,z,X]);if(V)return V;if($&&typeof $==="object"&&$.name==="HTTPException"){let W=$;if(console.error(`HTTPException on path: ${z}`,{status:W.status,message:W.message,cause:W.cause,res:W.res,stack:W.stack}),W.res)return W.res;return Q==="json"?Response.json({error:W.message},{status:W.status}):new Response(W.message,{status:W.status})}let G=$ instanceof Error?$.message:"Internal Server Error",U=$ instanceof Error?$.stack:void 0;if(console.error(`Error on path: ${z}`,{message:G,stack:U}),Q==="json"){let W={error:G,...!1,path:z};return Response.json(W,{status:500,headers:{"Content-Type":"application/json"}})}else{let W=`Error: ${G}`;return new Response(W,{headers:{"Content-Type":"text/plain"},status:500})}}mount($,z){let X=typeof z==="function"?z:z.fetch(),Z=$.endsWith("/*")?$.slice(0,-1):$,Q=Z==="/"?0:Z.length;this.all($,(V)=>{let G=new URL(V.req.url);G.pathname=G.pathname.slice(Q)||"/";let U=new Request(G,V.req);return X(U,V.server,V.env,V.executionContext)})}route($,z){$=$&&$.length>0?$:z?.prefixApiUrl;let X=z?.tempRoutes??new Map;for(let[Z,Q]of X.entries()){let V=Z.replace(/::\w+$/,""),G=`${$}${V}`,U=Q.handlers.slice(0,-1);this.router.addMiddleware(G,U);let W=Q.handlers[Q.handlers.length-1],F=Q.method;try{this.router.add(F,G,W)}catch(Y){console.error(`Error inserting ${G}:`,Y)}}for(let[Z,Q]of z?.tempMiddlewares?.entries()){let V=Z==="/"?$||"/":`${$}${Z}`;this.router.addMiddleware(V,Q)}return z=null,this}register($){let z=new M,X=()=>{};return this}sub($,z){return this.mount($,z)}addMiddlewareInRouter($,z){this.router.addMiddleware($,z)}addRoute($,z,X){if(typeof z!=="string")throw Error(`Error in ${X[X.length-1]}: Path must be a string. Received: ${typeof z}`);if(typeof $!=="string")throw Error(`Error in addRoute: Method must be a string. Received: ${typeof $}`);this.tempRoutes?.set(z+"::"+$,{method:$,handlers:X});let Z=X.slice(0,-1),Q=X[X.length-1];if(Z.length>0)this.addMiddlewareInRouter(z,Z);try{$=$==="ANY"?"ALL":$,this.router.add($,z,Q)}catch(V){console.error(`Error inserting ${z}:`,V)}}use($,...z){if(typeof $==="string"){let X=$==="/"?"/":$;if(!this.tempMiddlewares?.has(X))this.tempMiddlewares?.set(X,[]);this.tempMiddlewares?.get(X).push(...z),this.router.addMiddleware(X,z)}else if(typeof $==="function"){let X=[$,...z];if(!this.tempMiddlewares?.has("/"))this.tempMiddlewares?.set("/",[]);this.tempMiddlewares?.get("/").push(...z),this.router.addMiddleware("/",X)}return this}routeNotFound($){return this.routeNotFoundFunc=$,this}onMethod($,z,...X){let Z=Array.isArray($)?$:[$];for(let Q of Z){let V=Q.toLowerCase();if(V in this)this[V](z,...X);else this.addRoute(Q.toUpperCase(),z,X)}return this}on($,z){return this.emitter.on($,z),this}emit($,...z){return this.emitter.emit($,...z),this}}export{M as default};
package/dist/types.d.ts CHANGED
@@ -2,7 +2,6 @@ import { Server } from "bun";
2
2
  import { Router } from "./router/interface";
3
3
  import Diesel from "./main";
4
4
  import type { Context } from "./ctx";
5
- export type { Context };
6
5
  export type ContextType = Context;
7
6
  export type { Diesel };
8
7
  export type listenCalllBackType = () => void;
@@ -11,7 +10,7 @@ export type RouteHandler = (path: string, ...handlers: handlerFunction[] | middl
11
10
  export type middlewareFunc = (ctx: Context | Request | any, server: Server) => void | undefined | Response | Promise<undefined | void | Response>;
12
11
  export type HookFunction = (ctx: Context, result?: Response | null, server?: Server) => undefined | void | null | Response | Promise<void | null | undefined | Response>;
13
12
  export type RouteNotFoundHandler = (ctx: Context) => Response | void | undefined | Promise<Response>;
14
- export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD" | "ANY" | "PROPFIND";
13
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD" | "ANY" | "PROPFIND" | "ALL";
15
14
  export type HttpMethodOfApp = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'any' | 'propfind';
16
15
  export type HttpMethodLower = Lowercase<HttpMethod>;
17
16
  export type HookType = "onRequest" | "preHandler" | "postHandler" | "onSend" | "onError" | "onClose";
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './dist/types';
2
2
 
3
3
  export { default as Diesel } from './dist/main';
4
- export { default as Context } from './dist/ctx';
4
+ export { Context } from './dist/ctx';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import Diesel from './dist/main.js'
2
+ import { Context } from './dist/ctx.js'
2
3
 
3
-
4
- export {Diesel}
4
+ export { Diesel, Context }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diesel-core",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",