diesel-core 1.4.7 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ctx.js +54 -1
- package/dist/handleRequest.d.ts +5 -7
- package/dist/handleRequest.js +54 -1
- package/dist/main.d.ts +6 -0
- package/dist/main.js +172 -3
- package/dist/middlewares/cors/cors.js +1 -1
- package/dist/request_pipeline.js +170 -0
- package/dist/router/smart-router/router.d.ts +11 -0
- package/dist/trie.d.ts +4 -3
- package/dist/trie.js +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/urls.d.ts +39 -0
- package/dist/utils/urls.js +1 -0
- package/package.json +12 -12
package/dist/ctx.js
CHANGED
|
@@ -1 +1,54 @@
|
|
|
1
|
-
var
|
|
1
|
+
var B1=Object.create;var{getPrototypeOf:U1,defineProperty:W,getOwnPropertyNames:P,getOwnPropertyDescriptor:H1}=Object,c=Object.prototype.hasOwnProperty;var M1=(f,v,g)=>{g=f!=null?B1(U1(f)):{};let A=v||!f||!f.__esModule?W(g,"default",{value:f,enumerable:!0}):g;for(let C of P(f))if(!c.call(A,C))W(A,C,{get:()=>f[C],enumerable:!0});return A},_=new WeakMap,N1=(f)=>{var v=_.get(f),g;if(v)return v;if(v=W({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")P(f).map((A)=>!c.call(v,A)&&W(v,A,{get:()=>f[A],enumerable:!(g=H1(f,A))||g.enumerable}));return _.set(f,v),v},L=(f,v)=>()=>(v||f((v={exports:{}}).exports,v),v.exports);var F1=(f,v)=>{for(var g in v)W(f,g,{get:v[g],enumerable:!0,configurable:!0,set:(A)=>v[g]=()=>A})};var R1=(f,v)=>()=>(f&&(v=f(f=0)),v);var D1=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(v,g)=>(typeof require!=="undefined"?require:v)[g]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var t={};F1(t,{sep:()=>a,resolve:()=>M,relative:()=>m,posix:()=>p,parse:()=>s,normalize:()=>q,join:()=>r,isAbsolute:()=>h,format:()=>e,extname:()=>i,dirname:()=>l,delimiter:()=>o,default:()=>q1,basename:()=>n,_makeLong:()=>d});function X(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function T(f,v){var g="",A=0,C=-1,w=0,j;for(var z=0;z<=f.length;++z){if(z<f.length)j=f.charCodeAt(z);else if(j===47)break;else j=47;if(j===47){if(C===z-1||w===1);else if(C!==z-1&&w===2){if(g.length<2||A!==2||g.charCodeAt(g.length-1)!==46||g.charCodeAt(g.length-2)!==46){if(g.length>2){var Z=g.lastIndexOf("/");if(Z!==g.length-1){if(Z===-1)g="",A=0;else g=g.slice(0,Z),A=g.length-1-g.lastIndexOf("/");C=z,w=0;continue}}else if(g.length===2||g.length===1){g="",A=0,C=z,w=0;continue}}if(v){if(g.length>0)g+="/..";else g="..";A=2}}else{if(g.length>0)g+="/"+f.slice(C+1,z);else g=f.slice(C+1,z);A=z-C-1}C=z,w=0}else if(j===46&&w!==-1)++w;else w=-1}return g}function L1(f,v){var g=v.dir||v.root,A=v.base||(v.name||"")+(v.ext||"");if(!g)return A;if(g===v.root)return g+A;return g+f+A}function M(){var f="",v=!1,g;for(var A=arguments.length-1;A>=-1&&!v;A--){var C;if(A>=0)C=arguments[A];else{if(g===void 0)g=process.cwd();C=g}if(X(C),C.length===0)continue;f=C+"/"+f,v=C.charCodeAt(0)===47}if(f=T(f,!v),v)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function q(f){if(X(f),f.length===0)return".";var v=f.charCodeAt(0)===47,g=f.charCodeAt(f.length-1)===47;if(f=T(f,!v),f.length===0&&!v)f=".";if(f.length>0&&g)f+="/";if(v)return"/"+f;return f}function h(f){return X(f),f.length>0&&f.charCodeAt(0)===47}function r(){if(arguments.length===0)return".";var f;for(var v=0;v<arguments.length;++v){var g=arguments[v];if(X(g),g.length>0)if(f===void 0)f=g;else f+="/"+g}if(f===void 0)return".";return q(f)}function m(f,v){if(X(f),X(v),f===v)return"";if(f=M(f),v=M(v),f===v)return"";var g=1;for(;g<f.length;++g)if(f.charCodeAt(g)!==47)break;var A=f.length,C=A-g,w=1;for(;w<v.length;++w)if(v.charCodeAt(w)!==47)break;var j=v.length,z=j-w,Z=C<z?C:z,$=-1,b=0;for(;b<=Z;++b){if(b===Z){if(z>Z){if(v.charCodeAt(w+b)===47)return v.slice(w+b+1);else if(b===0)return v.slice(w+b)}else if(C>Z){if(f.charCodeAt(g+b)===47)$=b;else if(b===0)$=0}break}var Y=f.charCodeAt(g+b),K=v.charCodeAt(w+b);if(Y!==K)break;else if(Y===47)$=b}var J="";for(b=g+$+1;b<=A;++b)if(b===A||f.charCodeAt(b)===47)if(J.length===0)J+="..";else J+="/..";if(J.length>0)return J+v.slice(w+$);else{if(w+=$,v.charCodeAt(w)===47)++w;return v.slice(w)}}function d(f){return f}function l(f){if(X(f),f.length===0)return".";var v=f.charCodeAt(0),g=v===47,A=-1,C=!0;for(var w=f.length-1;w>=1;--w)if(v=f.charCodeAt(w),v===47){if(!C){A=w;break}}else C=!1;if(A===-1)return g?"/":".";if(g&&A===1)return"//";return f.slice(0,A)}function n(f,v){if(v!==void 0&&typeof v!=="string")throw new TypeError('"ext" argument must be a string');X(f);var g=0,A=-1,C=!0,w;if(v!==void 0&&v.length>0&&v.length<=f.length){if(v.length===f.length&&v===f)return"";var j=v.length-1,z=-1;for(w=f.length-1;w>=0;--w){var Z=f.charCodeAt(w);if(Z===47){if(!C){g=w+1;break}}else{if(z===-1)C=!1,z=w+1;if(j>=0)if(Z===v.charCodeAt(j)){if(--j===-1)A=w}else j=-1,A=z}}if(g===A)A=z;else if(A===-1)A=f.length;return f.slice(g,A)}else{for(w=f.length-1;w>=0;--w)if(f.charCodeAt(w)===47){if(!C){g=w+1;break}}else if(A===-1)C=!1,A=w+1;if(A===-1)return"";return f.slice(g,A)}}function i(f){X(f);var v=-1,g=0,A=-1,C=!0,w=0;for(var j=f.length-1;j>=0;--j){var z=f.charCodeAt(j);if(z===47){if(!C){g=j+1;break}continue}if(A===-1)C=!1,A=j+1;if(z===46){if(v===-1)v=j;else if(w!==1)w=1}else if(v!==-1)w=-1}if(v===-1||A===-1||w===0||w===1&&v===A-1&&v===g+1)return"";return f.slice(v,A)}function e(f){if(f===null||typeof f!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof f);return L1("/",f)}function s(f){X(f);var v={root:"",dir:"",base:"",ext:"",name:""};if(f.length===0)return v;var g=f.charCodeAt(0),A=g===47,C;if(A)v.root="/",C=1;else C=0;var w=-1,j=0,z=-1,Z=!0,$=f.length-1,b=0;for(;$>=C;--$){if(g=f.charCodeAt($),g===47){if(!Z){j=$+1;break}continue}if(z===-1)Z=!1,z=$+1;if(g===46){if(w===-1)w=$;else if(b!==1)b=1}else if(w!==-1)b=-1}if(w===-1||z===-1||b===0||b===1&&w===z-1&&w===j+1){if(z!==-1)if(j===0&&A)v.base=v.name=f.slice(1,z);else v.base=v.name=f.slice(j,z)}else{if(j===0&&A)v.name=f.slice(1,w),v.base=f.slice(1,z);else v.name=f.slice(j,w),v.base=f.slice(j,z);v.ext=f.slice(w,z)}if(j>0)v.dir=f.slice(0,j-1);else if(A)v.dir="/";return v}var a="/",o=":",p,q1;var f1=R1(()=>{p=((f)=>(f.posix=f,f))({resolve:M,normalize:q,isAbsolute:h,join:r,relative:m,_makeLong:d,dirname:l,basename:n,extname:i,format:e,parse:s,sep:a,delimiter:o,win32:null,posix:null}),q1=p});var A1=L((E1)=>{var x1=/[|\\{}()[\]^$+*?.]/g,O1=Object.prototype.hasOwnProperty,O=function(f,v){return O1.apply(f,[v])};E1.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(x1,"\\$&")};var y1={"&":"&","<":"<",">":">",'"':""","'":"'"},I1=/[&<>'"]/g;function S1(f){return y1[f]||f}var k1=`var _ENCODE_HTML_RULES = {
|
|
2
|
+
"&": "&"
|
|
3
|
+
, "<": "<"
|
|
4
|
+
, ">": ">"
|
|
5
|
+
, '"': """
|
|
6
|
+
, "'": "'"
|
|
7
|
+
}
|
|
8
|
+
, _MATCH_HTML = /[&<>'"]/g;
|
|
9
|
+
function encode_char(c) {
|
|
10
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
11
|
+
};
|
|
12
|
+
`;E1.escapeXML=function(f){return f==null?"":String(f).replace(I1,S1)};function g1(){return Function.prototype.toString.call(this)+`;
|
|
13
|
+
`+k1}try{if(typeof Object.defineProperty==="function")Object.defineProperty(E1.escapeXML,"toString",{value:g1});else E1.escapeXML.toString=g1}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}E1.shallowCopy=function(f,v){if(v=v||{},f!==null&&f!==void 0)for(var g in v){if(!O(v,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=v[g]}return f};E1.shallowCopyFromList=function(f,v,g){if(g=g||[],v=v||{},f!==null&&f!==void 0)for(var A=0;A<g.length;A++){var C=g[A];if(typeof v[C]!="undefined"){if(!O(v,C))continue;if(C==="__proto__"||C==="constructor")continue;f[C]=v[C]}}return f};E1.cache={_data:{},set:function(f,v){this._data[f]=v},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};E1.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(v){return v[1].toUpperCase()})};E1.createNullProtoObjWherePossible=function(){if(typeof Object.create=="function")return function(){return Object.create(null)};if(!({__proto__:null}instanceof Object))return function(){return{__proto__:null}};return function(){return{}}}();E1.hasOwnOnlyObject=function(f){var v=E1.createNullProtoObjWherePossible();for(var g in f)if(O(f,g))v[g]=f[g];return v}});var C1=L((Q0,r1)=>{r1.exports={name:"ejs",description:"Embedded JavaScript templates",keywords:["template","engine","ejs"],version:"3.1.10",author:"Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"npx jake test"}}});var X1=L((J1)=>{var S=(()=>({})),B=(f1(),N1(t)),V=A1(),w1=!1,m1=C1().version,d1="<",l1=">",n1="%",Z1="locals",i1="ejs",e1="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",$1=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],s1=$1.concat("cache"),b1=/^\uFEFF/,y=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;J1.cache=V.cache;J1.fileLoader=S.readFileSync;J1.localsName=Z1;J1.promiseImpl=new Function("return this;")().Promise;J1.resolveInclude=function(f,v,g){var{dirname:A,extname:C,resolve:w}=B,j=w(g?v:A(v),f),z=C(f);if(!z)j+=".ejs";return j};function j1(f,v){var g;if(v.some(function(A){return g=J1.resolveInclude(f,A,!0),S.existsSync(g)}))return g}function a1(f,v){var g,A,C=v.views,w=/^[A-Za-z]+:\\|^\//.exec(f);if(w&&w.length)if(f=f.replace(/^\/*/,""),Array.isArray(v.root))g=j1(f,v.root);else g=J1.resolveInclude(f,v.root||"/",!0);else{if(v.filename){if(A=J1.resolveInclude(f,v.filename),S.existsSync(A))g=A}if(!g&&Array.isArray(C))g=j1(f,C);if(!g&&typeof v.includer!=="function")throw new Error('Could not find the include file "'+v.escapeFunction(f)+'"')}return g}function U(f,v){var g,A=f.filename,C=arguments.length>1;if(f.cache){if(!A)throw new Error("cache option requires a filename");if(g=J1.cache.get(A),g)return g;if(!C)v=z1(A).toString().replace(b1,"")}else if(!C){if(!A)throw new Error("Internal EJS error: no file name or template provided");v=z1(A).toString().replace(b1,"")}if(g=J1.compile(v,f),f.cache)J1.cache.set(A,g);return g}function o1(f,v,g){var A;if(!g)if(typeof J1.promiseImpl=="function")return new J1.promiseImpl(function(C,w){try{A=U(f)(v),C(A)}catch(j){w(j)}});else throw new Error("Please provide a callback function");else{try{A=U(f)(v)}catch(C){return g(C)}g(null,A)}}function z1(f){return J1.fileLoader(f)}function p1(f,v){var g=V.shallowCopy(V.createNullProtoObjWherePossible(),v);if(g.filename=a1(f,g),typeof v.includer==="function"){var A=v.includer(f,g.filename);if(A){if(A.filename)g.filename=A.filename;if(A.template)return U(g,A.template)}}return U(g)}function K1(f,v,g,A,C){var w=v.split(`
|
|
14
|
+
`),j=Math.max(A-3,0),z=Math.min(w.length,A+3),Z=C(g),$=w.slice(j,z).map(function(b,Y){var K=Y+j+1;return(K==A?" >> ":" ")+K+"| "+b}).join(`
|
|
15
|
+
`);throw f.path=Z,f.message=(Z||"ejs")+":"+A+`
|
|
16
|
+
`+$+`
|
|
17
|
+
|
|
18
|
+
`+f.message,f}function Y1(f){return f.replace(/;(\s*$)/,"$1")}J1.compile=function f(v,g){var A;if(g&&g.scope){if(!w1)console.warn("`scope` option is deprecated and will be removed in EJS 3"),w1=!0;if(!g.context)g.context=g.scope;delete g.scope}return A=new G(v,g),A.compile()};J1.render=function(f,v,g){var A=v||V.createNullProtoObjWherePossible(),C=g||V.createNullProtoObjWherePossible();if(arguments.length==2)V.shallowCopyFromList(C,A,$1);return U(C,f)(A)};J1.renderFile=function(){var f=Array.prototype.slice.call(arguments),v=f.shift(),g,A={filename:v},C,w;if(typeof arguments[arguments.length-1]=="function")g=f.pop();if(f.length){if(C=f.shift(),f.length)V.shallowCopy(A,f.pop());else{if(C.settings){if(C.settings.views)A.views=C.settings.views;if(C.settings["view cache"])A.cache=!0;if(w=C.settings["view options"],w)V.shallowCopy(A,w)}V.shallowCopyFromList(A,C,s1)}A.filename=v}else C=V.createNullProtoObjWherePossible();return o1(A,C,g)};J1.Template=G;J1.clearCache=function(){J1.cache.reset()};function G(f,v){var g=V.hasOwnOnlyObject(v),A=V.createNullProtoObjWherePossible();if(this.templateText=f,this.mode=null,this.truncate=!1,this.currentLine=1,this.source="",A.client=g.client||!1,A.escapeFunction=g.escape||g.escapeFunction||V.escapeXML,A.compileDebug=g.compileDebug!==!1,A.debug=!!g.debug,A.filename=g.filename,A.openDelimiter=g.openDelimiter||J1.openDelimiter||d1,A.closeDelimiter=g.closeDelimiter||J1.closeDelimiter||l1,A.delimiter=g.delimiter||J1.delimiter||n1,A.strict=g.strict||!1,A.context=g.context,A.cache=g.cache||!1,A.rmWhitespace=g.rmWhitespace,A.root=g.root,A.includer=g.includer,A.outputFunctionName=g.outputFunctionName,A.localsName=g.localsName||J1.localsName||Z1,A.views=g.views,A.async=g.async,A.destructuredLocals=g.destructuredLocals,A.legacyInclude=typeof g.legacyInclude!="undefined"?!!g.legacyInclude:!0,A.strict)A._with=!1;else A._with=typeof g._with!="undefined"?g._with:!0;this.opts=A,this.regex=this.createRegex()}G.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};G.prototype={createRegex:function(){var f=e1,v=V.escapeRegExpChars(this.opts.delimiter),g=V.escapeRegExpChars(this.opts.openDelimiter),A=V.escapeRegExpChars(this.opts.closeDelimiter);return f=f.replace(/%/g,v).replace(/</g,g).replace(/>/g,A),new RegExp(f)},compile:function(){var f,v,g=this.opts,A="",C="",w=g.escapeFunction,j,z=g.filename?JSON.stringify(g.filename):"undefined";if(!this.source){if(this.generateSource(),A+=` var __output = "";
|
|
19
|
+
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
+
`,g.outputFunctionName){if(!y.test(g.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");A+=" var "+g.outputFunctionName+` = __append;
|
|
21
|
+
`}if(g.localsName&&!y.test(g.localsName))throw new Error("localsName is not a valid JS identifier.");if(g.destructuredLocals&&g.destructuredLocals.length){var Z=" var __locals = ("+g.localsName+` || {}),
|
|
22
|
+
`;for(var $=0;$<g.destructuredLocals.length;$++){var b=g.destructuredLocals[$];if(!y.test(b))throw new Error("destructuredLocals["+$+"] is not a valid JS identifier.");if($>0)Z+=`,
|
|
23
|
+
`;Z+=b+" = __locals."+b}A+=Z+`;
|
|
24
|
+
`}if(g._with!==!1)A+=" with ("+g.localsName+` || {}) {
|
|
25
|
+
`,C+=` }
|
|
26
|
+
`;C+=` return __output;
|
|
27
|
+
`,this.source=A+this.source+C}if(g.compileDebug)f=`var __line = 1
|
|
28
|
+
, __lines = `+JSON.stringify(this.templateText)+`
|
|
29
|
+
, __filename = `+z+`;
|
|
30
|
+
try {
|
|
31
|
+
`+this.source+`} catch (e) {
|
|
32
|
+
rethrow(e, __lines, __filename, __line, escapeFn);
|
|
33
|
+
}
|
|
34
|
+
`;else f=this.source;if(g.client){if(f="escapeFn = escapeFn || "+w.toString()+`;
|
|
35
|
+
`+f,g.compileDebug)f="rethrow = rethrow || "+K1.toString()+`;
|
|
36
|
+
`+f}if(g.strict)f=`"use strict";
|
|
37
|
+
`+f;if(g.debug)console.log(f);if(g.compileDebug&&g.filename)f=f+`
|
|
38
|
+
//# sourceURL=`+z+`
|
|
39
|
+
`;try{if(g.async)try{j=new Function("return (async function(){}).constructor;")()}catch(Q){if(Q instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw Q}else j=Function;v=new j(g.localsName+", escapeFn, include, rethrow",f)}catch(Q){if(Q instanceof SyntaxError){if(g.filename)Q.message+=" in "+g.filename;if(Q.message+=` while compiling ejs
|
|
40
|
+
|
|
41
|
+
`,Q.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
|
+
`,Q.message+="https://github.com/RyanZim/EJS-Lint",!g.async)Q.message+=`
|
|
43
|
+
`,Q.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw Q}var Y=g.client?v:function Q(H){var R=function(W1,E){var D=V.shallowCopy(V.createNullProtoObjWherePossible(),H);if(E)D=V.shallowCopy(D,E);return p1(W1,g)(D)};return v.apply(g.context,[H||V.createNullProtoObjWherePossible(),w,R,K1])};if(g.filename&&typeof Object.defineProperty==="function"){var K=g.filename,J=B.basename(K,B.extname(K));try{Object.defineProperty(Y,"name",{value:J,writable:!1,enumerable:!1,configurable:!0})}catch(Q){}}return Y},generateSource:function(){var f=this.opts;if(f.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
|
+
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var v=this,g=this.parseTemplateText(),A=this.opts.delimiter,C=this.opts.openDelimiter,w=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(j,z){var Z;if(j.indexOf(C+A)===0&&j.indexOf(C+A+A)!==0){if(Z=g[z+2],!(Z==A+w||Z=="-"+A+w||Z=="_"+A+w))throw new Error('Could not find matching close tag for "'+j+'".')}v.scanLine(j)})},parseTemplateText:function(){var f=this.templateText,v=this.regex,g=v.exec(f),A=[],C;while(g){if(C=g.index,C!==0)A.push(f.substring(0,C)),f=f.slice(C);A.push(g[0]),f=f.slice(g[0].length),g=v.exec(f)}if(f)A.push(f);return A},_addOutput:function(f){if(this.truncate)f=f.replace(/^(?:\r\n|\r|\n)/,""),this.truncate=!1;if(!f)return f;f=f.replace(/\\/g,"\\\\"),f=f.replace(/\n/g,"\\n"),f=f.replace(/\r/g,"\\r"),f=f.replace(/"/g,"\\\""),this.source+=' ; __append("'+f+`")
|
|
45
|
+
`},scanLine:function(f){var v=this,g=this.opts.delimiter,A=this.opts.openDelimiter,C=this.opts.closeDelimiter,w=0;switch(w=f.split(`
|
|
46
|
+
`).length-1,f){case A+g:case A+g+"_":this.mode=G.modes.EVAL;break;case A+g+"=":this.mode=G.modes.ESCAPED;break;case A+g+"-":this.mode=G.modes.RAW;break;case A+g+"#":this.mode=G.modes.COMMENT;break;case A+g+g:this.mode=G.modes.LITERAL,this.source+=' ; __append("'+f.replace(A+g+g,A+g)+`")
|
|
47
|
+
`;break;case g+g+C:this.mode=G.modes.LITERAL,this.source+=' ; __append("'+f.replace(g+g+C,g+C)+`")
|
|
48
|
+
`;break;case g+C:case"-"+g+C:case"_"+g+C:if(this.mode==G.modes.LITERAL)this._addOutput(f);this.mode=null,this.truncate=f.indexOf("-")===0||f.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case G.modes.EVAL:case G.modes.ESCAPED:case G.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
|
|
49
|
+
`))f+=`
|
|
50
|
+
`}switch(this.mode){case G.modes.EVAL:this.source+=" ; "+f+`
|
|
51
|
+
`;break;case G.modes.ESCAPED:this.source+=" ; __append(escapeFn("+Y1(f)+`))
|
|
52
|
+
`;break;case G.modes.RAW:this.source+=" ; __append("+Y1(f)+`)
|
|
53
|
+
`;break;case G.modes.COMMENT:break;case G.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(v.opts.compileDebug&&w)this.currentLine+=w,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
+
`}};J1.escapeXML=V.escapeXML;J1.__express=J1.renderFile;J1.VERSION=m1;J1.name=i1;if(typeof window!="undefined")window.ejs=J1});function u(f){switch(f.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 k=null;async function j0(){if(!k){let f=await Promise.resolve().then(() => M1(X1(),1));k=f.default||f}return k}var z0={string:"text/plain; charset=utf-8",object:"application/json; charset=utf-8",Uint8Array:"application/octet-stream",ArrayBuffer:"application/octet-stream"};function K0(f,v,g,A){let C=null,w=null,j=null,z=null,Z={},$=null;return{req:f,server:v,pathname:g,status:200,headers:new Headers,setHeader(b,Y){return this.headers.set(b,Y),this},removeHeader(b){return this.headers.delete(b),this},set(b,Y){return Z[b]=Y,this},get(b){return Z[b]},get ip(){return this.server.requestIP(f)?.address??null},get url(){if(!$)$=new URL(f.url);return $},get query(){if(!C){if(!this.url.search)return{};C=Object.fromEntries(this.url.searchParams)}return C},get params(){if(!w&&A)try{w=Z0(A,g)}catch(b){let Y=b instanceof Error?b.message:String(b);throw new Error(`Failed to extract route parameters: ${Y}`)}return w??{}},get body(){if(f.method==="GET")return Promise.resolve({});if(!z)z=(async()=>{try{let b=await $0(f);if(b.error)throw new Error(b.error);return Object.keys(b).length===0?null:b}catch(b){throw new Error("Invalid request body format")}})();return z},text(b,Y=200){if(this.status=Y,!this.headers.has("Content-Type"))this.headers.set("Content-Type","text/plain; charset=utf-8");return new Response(b,{status:Y,headers:this.headers})},send(b,Y=200){this.status=Y;let K;if(b instanceof Uint8Array)K="Uint8Array";else if(b instanceof ArrayBuffer)K="ArrayBuffer";else K=typeof b;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",z0[K]??"text/plain; charset=utf-8");let J=K==="object"&&b!==null?JSON.stringify(b):b;return new Response(J,{status:Y,headers:this.headers})},json(b,Y=200){if(this.status=Y,!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return Response.json(b,{status:Y,headers:this.headers})},file(b,Y,K=200){this.status=K;let J=Bun.file(b);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",Y??u(b));return new Response(J,{status:K,headers:this.headers})},async ejs(b,Y={},K=200){this.status=K;let J=await j0();try{let Q=await Bun.file(b).text(),H=J.render(Q,Y),R=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(H,{status:K,headers:R})}catch(Q){return console.error("EJS Rendering Error:",Q),new Response("Error rendering template",{status:500})}},redirect(b,Y=302){return this.status=Y,this.headers.set("Location",b),new Response(null,{status:Y,headers:this.headers})},stream(b){let Y=new Headers(this.headers),K=new ReadableStream({async start(J){await b(J),J.close()}});return new Response(K,{headers:Y})},yieldStream(b){return new Response("not working stream yet.")},setCookie(b,Y,K={}){let J=`${encodeURIComponent(b)}=${encodeURIComponent(Y)}`;if(K.maxAge)J+=`; Max-Age=${K.maxAge}`;if(K.expires)J+=`; Expires=${K.expires.toUTCString()}`;if(K.path)J+=`; Path=${K.path}`;if(K.domain)J+=`; Domain=${K.domain}`;if(K.secure)J+="; Secure";if(K.httpOnly)J+="; HttpOnly";if(K.sameSite)J+=`; SameSite=${K.sameSite}`;return this.headers.append("Set-Cookie",J),this},get cookies(){if(!j){let b=this.req.headers.get("cookie");j=b?Y0(b):{}}return j}}}function Y0(f){return Object.fromEntries(f.split(";").map((v)=>{let[g,...A]=v.trim().split("=");return[g,decodeURIComponent(A.join("="))]}))}function Z0(f,v){let g={},A=f.split("/"),[C]=v.split("?"),w=C.split("/");if(A.length!==w.length)return null;for(let j=0;j<A.length;j++){let z=A[j];if(z.charCodeAt(0)===58)g[z.slice(1)]=w[j]}return g}async function $0(f){let v=f.headers.get("Content-Type")||"";if(!v)return{};if(f.headers.get("Content-Length")==="0"||!f.body)return{};if(v.startsWith("application/json"))return await f.json();if(v.startsWith("application/x-www-form-urlencoded")){let A=await f.text();return Object.fromEntries(new URLSearchParams(A))}if(v.startsWith("multipart/form-data")){let A=await f.formData(),C={};for(let[w,j]of A.entries())C[w]=j;return C}return{error:"Unknown request body type"}}export{Z0 as extractDynamicParams,K0 as default};
|
package/dist/handleRequest.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { BunRequest, Server } from "bun";
|
|
2
2
|
import type { ContextType, DieselT, HookType } from "./types";
|
|
3
|
-
|
|
4
|
-
export declare function parseRequestUrl(rawUrl: string): string;
|
|
5
|
-
export default function handleRequest(req: BunRequest, server: Server, diesel: DieselT): Promise<Response>;
|
|
3
|
+
export default function handleRequest(req: BunRequest, server: Server, diesel: DieselT): Promise<Response | undefined>;
|
|
6
4
|
export declare function runHooks<T extends any[]>(label: HookType, hooksArray: any, args: T): Promise<any>;
|
|
7
|
-
export declare function runMiddlewares(diesel: DieselT, pathname: string, ctx: ContextType
|
|
5
|
+
export declare function runMiddlewares(diesel: DieselT, pathname: string, ctx: ContextType): Promise<Response | null>;
|
|
8
6
|
export declare function executeBunMiddlewares(middlewares: Function[], req: BunRequest, server: Server): Promise<any>;
|
|
9
|
-
export declare function runFilter(diesel: DieselT, path: string, ctx: ContextType
|
|
10
|
-
export declare function handleFilterRequest(diesel: DieselT, path: string, ctx: ContextType
|
|
7
|
+
export declare function runFilter(diesel: DieselT, path: string, ctx: ContextType): Promise<any>;
|
|
8
|
+
export declare function handleFilterRequest(diesel: DieselT, path: string, ctx: ContextType): Promise<Response | undefined>;
|
|
11
9
|
export declare function handleBunFilterRequest(diesel: DieselT, path: string, req: BunRequest, server: Server): Promise<Response | undefined>;
|
|
12
|
-
export declare function handleRouteNotFound(diesel: DieselT, ctx: ContextType, pathname: string): Promise<Response>;
|
|
10
|
+
export declare function handleRouteNotFound(diesel: DieselT, ctx: ContextType, pathname: string): Promise<Response | undefined>;
|
|
13
11
|
export declare function generateErrorResponse(status: number, error: string): Response;
|
|
14
12
|
export declare function handleStaticFiles(diesel: DieselT, pathname: string, ctx: ContextType): Promise<Response | null>;
|
package/dist/handleRequest.js
CHANGED
|
@@ -1 +1,54 @@
|
|
|
1
|
-
var
|
|
1
|
+
var L1=Object.create;var{getPrototypeOf:F1,defineProperty:M,getOwnPropertyNames:h,getOwnPropertyDescriptor:O1}=Object,u=Object.prototype.hasOwnProperty;var D1=(f,z,g)=>{g=f!=null?L1(F1(f)):{};let Y=z||!f||!f.__esModule?M(g,"default",{value:f,enumerable:!0}):g;for(let Z of h(f))if(!u.call(Y,Z))M(Y,Z,{get:()=>f[Z],enumerable:!0});return Y},m=new WeakMap,S1=(f)=>{var z=m.get(f),g;if(z)return z;if(z=M({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")h(f).map((Y)=>!u.call(z,Y)&&M(z,Y,{get:()=>f[Y],enumerable:!(g=O1(f,Y))||g.enumerable}));return m.set(f,z),z},E=(f,z)=>()=>(z||f((z={exports:{}}).exports,z),z.exports);var E1=(f,z)=>{for(var g in z)M(f,g,{get:z[g],enumerable:!0,configurable:!0,set:(Y)=>z[g]=()=>Y})};var b1=(f,z)=>()=>(f&&(z=f(f=0)),z);var _1=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(z,g)=>(typeof require!=="undefined"?require:z)[g]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var z1={};E1(z1,{sep:()=>e,resolve:()=>L,relative:()=>r,posix:()=>g1,parse:()=>t,normalize:()=>b,join:()=>n,isAbsolute:()=>i,format:()=>a,extname:()=>s,dirname:()=>o,delimiter:()=>f1,default:()=>q1,basename:()=>p,_makeLong:()=>l});function U(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function d(f,z){var g="",Y=0,Z=-1,$=0,J;for(var V=0;V<=f.length;++V){if(V<f.length)J=f.charCodeAt(V);else if(J===47)break;else J=47;if(J===47){if(Z===V-1||$===1);else if(Z!==V-1&&$===2){if(g.length<2||Y!==2||g.charCodeAt(g.length-1)!==46||g.charCodeAt(g.length-2)!==46){if(g.length>2){var G=g.lastIndexOf("/");if(G!==g.length-1){if(G===-1)g="",Y=0;else g=g.slice(0,G),Y=g.length-1-g.lastIndexOf("/");Z=V,$=0;continue}}else if(g.length===2||g.length===1){g="",Y=0,Z=V,$=0;continue}}if(z){if(g.length>0)g+="/..";else g="..";Y=2}}else{if(g.length>0)g+="/"+f.slice(Z+1,V);else g=f.slice(Z+1,V);Y=V-Z-1}Z=V,$=0}else if(J===46&&$!==-1)++$;else $=-1}return g}function R1(f,z){var g=z.dir||z.root,Y=z.base||(z.name||"")+(z.ext||"");if(!g)return Y;if(g===z.root)return g+Y;return g+f+Y}function L(){var f="",z=!1,g;for(var Y=arguments.length-1;Y>=-1&&!z;Y--){var Z;if(Y>=0)Z=arguments[Y];else{if(g===void 0)g=process.cwd();Z=g}if(U(Z),Z.length===0)continue;f=Z+"/"+f,z=Z.charCodeAt(0)===47}if(f=d(f,!z),z)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function b(f){if(U(f),f.length===0)return".";var z=f.charCodeAt(0)===47,g=f.charCodeAt(f.length-1)===47;if(f=d(f,!z),f.length===0&&!z)f=".";if(f.length>0&&g)f+="/";if(z)return"/"+f;return f}function i(f){return U(f),f.length>0&&f.charCodeAt(0)===47}function n(){if(arguments.length===0)return".";var f;for(var z=0;z<arguments.length;++z){var g=arguments[z];if(U(g),g.length>0)if(f===void 0)f=g;else f+="/"+g}if(f===void 0)return".";return b(f)}function r(f,z){if(U(f),U(z),f===z)return"";if(f=L(f),z=L(z),f===z)return"";var g=1;for(;g<f.length;++g)if(f.charCodeAt(g)!==47)break;var Y=f.length,Z=Y-g,$=1;for(;$<z.length;++$)if(z.charCodeAt($)!==47)break;var J=z.length,V=J-$,G=Z<V?Z:V,Q=-1,A=0;for(;A<=G;++A){if(A===G){if(V>G){if(z.charCodeAt($+A)===47)return z.slice($+A+1);else if(A===0)return z.slice($+A)}else if(Z>G){if(f.charCodeAt(g+A)===47)Q=A;else if(A===0)Q=0}break}var j=f.charCodeAt(g+A),X=z.charCodeAt($+A);if(j!==X)break;else if(j===47)Q=A}var W="";for(A=g+Q+1;A<=Y;++A)if(A===Y||f.charCodeAt(A)===47)if(W.length===0)W+="..";else W+="/..";if(W.length>0)return W+z.slice($+Q);else{if($+=Q,z.charCodeAt($)===47)++$;return z.slice($)}}function l(f){return f}function o(f){if(U(f),f.length===0)return".";var z=f.charCodeAt(0),g=z===47,Y=-1,Z=!0;for(var $=f.length-1;$>=1;--$)if(z=f.charCodeAt($),z===47){if(!Z){Y=$;break}}else Z=!1;if(Y===-1)return g?"/":".";if(g&&Y===1)return"//";return f.slice(0,Y)}function p(f,z){if(z!==void 0&&typeof z!=="string")throw new TypeError('"ext" argument must be a string');U(f);var g=0,Y=-1,Z=!0,$;if(z!==void 0&&z.length>0&&z.length<=f.length){if(z.length===f.length&&z===f)return"";var J=z.length-1,V=-1;for($=f.length-1;$>=0;--$){var G=f.charCodeAt($);if(G===47){if(!Z){g=$+1;break}}else{if(V===-1)Z=!1,V=$+1;if(J>=0)if(G===z.charCodeAt(J)){if(--J===-1)Y=$}else J=-1,Y=V}}if(g===Y)Y=V;else if(Y===-1)Y=f.length;return f.slice(g,Y)}else{for($=f.length-1;$>=0;--$)if(f.charCodeAt($)===47){if(!Z){g=$+1;break}}else if(Y===-1)Z=!1,Y=$+1;if(Y===-1)return"";return f.slice(g,Y)}}function s(f){U(f);var z=-1,g=0,Y=-1,Z=!0,$=0;for(var J=f.length-1;J>=0;--J){var V=f.charCodeAt(J);if(V===47){if(!Z){g=J+1;break}continue}if(Y===-1)Z=!1,Y=J+1;if(V===46){if(z===-1)z=J;else if($!==1)$=1}else if(z!==-1)$=-1}if(z===-1||Y===-1||$===0||$===1&&z===Y-1&&z===g+1)return"";return f.slice(z,Y)}function a(f){if(f===null||typeof f!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof f);return R1("/",f)}function t(f){U(f);var z={root:"",dir:"",base:"",ext:"",name:""};if(f.length===0)return z;var g=f.charCodeAt(0),Y=g===47,Z;if(Y)z.root="/",Z=1;else Z=0;var $=-1,J=0,V=-1,G=!0,Q=f.length-1,A=0;for(;Q>=Z;--Q){if(g=f.charCodeAt(Q),g===47){if(!G){J=Q+1;break}continue}if(V===-1)G=!1,V=Q+1;if(g===46){if($===-1)$=Q;else if(A!==1)A=1}else if($!==-1)A=-1}if($===-1||V===-1||A===0||A===1&&$===V-1&&$===J+1){if(V!==-1)if(J===0&&Y)z.base=z.name=f.slice(1,V);else z.base=z.name=f.slice(J,V)}else{if(J===0&&Y)z.name=f.slice(1,$),z.base=f.slice(1,V);else z.name=f.slice(J,$),z.base=f.slice(J,V);z.ext=f.slice($,V)}if(J>0)z.dir=f.slice(0,J-1);else if(Y)z.dir="/";return z}var e="/",f1=":",g1,q1;var Y1=b1(()=>{g1=((f)=>(f.posix=f,f))({resolve:L,normalize:b,isAbsolute:i,join:n,relative:r,_makeLong:l,dirname:o,basename:p,extname:s,format:a,parse:t,sep:e,delimiter:f1,win32:null,posix:null}),q1=g1});var A1=E((c1)=>{var T1=/[|\\{}()[\]^$+*?.]/g,P1=Object.prototype.hasOwnProperty,R=function(f,z){return P1.apply(f,[z])};c1.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(T1,"\\$&")};var I1={"&":"&","<":"<",">":">",'"':""","'":"'"},k1=/[&<>'"]/g;function y1(f){return I1[f]||f}var x1=`var _ENCODE_HTML_RULES = {
|
|
2
|
+
"&": "&"
|
|
3
|
+
, "<": "<"
|
|
4
|
+
, ">": ">"
|
|
5
|
+
, '"': """
|
|
6
|
+
, "'": "'"
|
|
7
|
+
}
|
|
8
|
+
, _MATCH_HTML = /[&<>'"]/g;
|
|
9
|
+
function encode_char(c) {
|
|
10
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
11
|
+
};
|
|
12
|
+
`;c1.escapeXML=function(f){return f==null?"":String(f).replace(k1,y1)};function Z1(){return Function.prototype.toString.call(this)+`;
|
|
13
|
+
`+x1}try{if(typeof Object.defineProperty==="function")Object.defineProperty(c1.escapeXML,"toString",{value:Z1});else c1.escapeXML.toString=Z1}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}c1.shallowCopy=function(f,z){if(z=z||{},f!==null&&f!==void 0)for(var g in z){if(!R(z,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=z[g]}return f};c1.shallowCopyFromList=function(f,z,g){if(g=g||[],z=z||{},f!==null&&f!==void 0)for(var Y=0;Y<g.length;Y++){var Z=g[Y];if(typeof z[Z]!="undefined"){if(!R(z,Z))continue;if(Z==="__proto__"||Z==="constructor")continue;f[Z]=z[Z]}}return f};c1.cache={_data:{},set:function(f,z){this._data[f]=z},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};c1.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(z){return z[1].toUpperCase()})};c1.createNullProtoObjWherePossible=function(){if(typeof Object.create=="function")return function(){return Object.create(null)};if(!({__proto__:null}instanceof Object))return function(){return{__proto__:null}};return function(){return{}}}();c1.hasOwnOnlyObject=function(f){var z=c1.createNullProtoObjWherePossible();for(var g in f)if(R(f,g))z[g]=f[g];return z}});var J1=E((D0,r1)=>{r1.exports={name:"ejs",description:"Embedded JavaScript templates",keywords:["template","engine","ejs"],version:"3.1.10",author:"Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"npx jake test"}}});var N1=E((w1)=>{var P=(()=>({})),K=(Y1(),S1(z1)),B=A1(),V1=!1,l1=J1().version,o1="<",p1=">",s1="%",B1="locals",a1="ejs",t1="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",C1=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],e1=C1.concat("cache"),X1=/^\uFEFF/,q=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;w1.cache=B.cache;w1.fileLoader=P.readFileSync;w1.localsName=B1;w1.promiseImpl=new Function("return this;")().Promise;w1.resolveInclude=function(f,z,g){var{dirname:Y,extname:Z,resolve:$}=K,J=$(g?z:Y(z),f),V=Z(f);if(!V)J+=".ejs";return J};function j1(f,z){var g;if(z.some(function(Y){return g=w1.resolveInclude(f,Y,!0),P.existsSync(g)}))return g}function f0(f,z){var g,Y,Z=z.views,$=/^[A-Za-z]+:\\|^\//.exec(f);if($&&$.length)if(f=f.replace(/^\/*/,""),Array.isArray(z.root))g=j1(f,z.root);else g=w1.resolveInclude(f,z.root||"/",!0);else{if(z.filename){if(Y=w1.resolveInclude(f,z.filename),P.existsSync(Y))g=Y}if(!g&&Array.isArray(Z))g=j1(f,Z);if(!g&&typeof z.includer!=="function")throw new Error('Could not find the include file "'+z.escapeFunction(f)+'"')}return g}function N(f,z){var g,Y=f.filename,Z=arguments.length>1;if(f.cache){if(!Y)throw new Error("cache option requires a filename");if(g=w1.cache.get(Y),g)return g;if(!Z)z=G1(Y).toString().replace(X1,"")}else if(!Z){if(!Y)throw new Error("Internal EJS error: no file name or template provided");z=G1(Y).toString().replace(X1,"")}if(g=w1.compile(z,f),f.cache)w1.cache.set(Y,g);return g}function g0(f,z,g){var Y;if(!g)if(typeof w1.promiseImpl=="function")return new w1.promiseImpl(function(Z,$){try{Y=N(f)(z),Z(Y)}catch(J){$(J)}});else throw new Error("Please provide a callback function");else{try{Y=N(f)(z)}catch(Z){return g(Z)}g(null,Y)}}function G1(f){return w1.fileLoader(f)}function z0(f,z){var g=B.shallowCopy(B.createNullProtoObjWherePossible(),z);if(g.filename=f0(f,g),typeof z.includer==="function"){var Y=z.includer(f,g.filename);if(Y){if(Y.filename)g.filename=Y.filename;if(Y.template)return N(g,Y.template)}}return N(g)}function Q1(f,z,g,Y,Z){var $=z.split(`
|
|
14
|
+
`),J=Math.max(Y-3,0),V=Math.min($.length,Y+3),G=Z(g),Q=$.slice(J,V).map(function(A,j){var X=j+J+1;return(X==Y?" >> ":" ")+X+"| "+A}).join(`
|
|
15
|
+
`);throw f.path=G,f.message=(G||"ejs")+":"+Y+`
|
|
16
|
+
`+Q+`
|
|
17
|
+
|
|
18
|
+
`+f.message,f}function W1(f){return f.replace(/;(\s*$)/,"$1")}w1.compile=function f(z,g){var Y;if(g&&g.scope){if(!V1)console.warn("`scope` option is deprecated and will be removed in EJS 3"),V1=!0;if(!g.context)g.context=g.scope;delete g.scope}return Y=new C(z,g),Y.compile()};w1.render=function(f,z,g){var Y=z||B.createNullProtoObjWherePossible(),Z=g||B.createNullProtoObjWherePossible();if(arguments.length==2)B.shallowCopyFromList(Z,Y,C1);return N(Z,f)(Y)};w1.renderFile=function(){var f=Array.prototype.slice.call(arguments),z=f.shift(),g,Y={filename:z},Z,$;if(typeof arguments[arguments.length-1]=="function")g=f.pop();if(f.length){if(Z=f.shift(),f.length)B.shallowCopy(Y,f.pop());else{if(Z.settings){if(Z.settings.views)Y.views=Z.settings.views;if(Z.settings["view cache"])Y.cache=!0;if($=Z.settings["view options"],$)B.shallowCopy(Y,$)}B.shallowCopyFromList(Y,Z,e1)}Y.filename=z}else Z=B.createNullProtoObjWherePossible();return g0(Y,Z,g)};w1.Template=C;w1.clearCache=function(){w1.cache.reset()};function C(f,z){var g=B.hasOwnOnlyObject(z),Y=B.createNullProtoObjWherePossible();if(this.templateText=f,this.mode=null,this.truncate=!1,this.currentLine=1,this.source="",Y.client=g.client||!1,Y.escapeFunction=g.escape||g.escapeFunction||B.escapeXML,Y.compileDebug=g.compileDebug!==!1,Y.debug=!!g.debug,Y.filename=g.filename,Y.openDelimiter=g.openDelimiter||w1.openDelimiter||o1,Y.closeDelimiter=g.closeDelimiter||w1.closeDelimiter||p1,Y.delimiter=g.delimiter||w1.delimiter||s1,Y.strict=g.strict||!1,Y.context=g.context,Y.cache=g.cache||!1,Y.rmWhitespace=g.rmWhitespace,Y.root=g.root,Y.includer=g.includer,Y.outputFunctionName=g.outputFunctionName,Y.localsName=g.localsName||w1.localsName||B1,Y.views=g.views,Y.async=g.async,Y.destructuredLocals=g.destructuredLocals,Y.legacyInclude=typeof g.legacyInclude!="undefined"?!!g.legacyInclude:!0,Y.strict)Y._with=!1;else Y._with=typeof g._with!="undefined"?g._with:!0;this.opts=Y,this.regex=this.createRegex()}C.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};C.prototype={createRegex:function(){var f=t1,z=B.escapeRegExpChars(this.opts.delimiter),g=B.escapeRegExpChars(this.opts.openDelimiter),Y=B.escapeRegExpChars(this.opts.closeDelimiter);return f=f.replace(/%/g,z).replace(/</g,g).replace(/>/g,Y),new RegExp(f)},compile:function(){var f,z,g=this.opts,Y="",Z="",$=g.escapeFunction,J,V=g.filename?JSON.stringify(g.filename):"undefined";if(!this.source){if(this.generateSource(),Y+=` var __output = "";
|
|
19
|
+
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
+
`,g.outputFunctionName){if(!q.test(g.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");Y+=" var "+g.outputFunctionName+` = __append;
|
|
21
|
+
`}if(g.localsName&&!q.test(g.localsName))throw new Error("localsName is not a valid JS identifier.");if(g.destructuredLocals&&g.destructuredLocals.length){var G=" var __locals = ("+g.localsName+` || {}),
|
|
22
|
+
`;for(var Q=0;Q<g.destructuredLocals.length;Q++){var A=g.destructuredLocals[Q];if(!q.test(A))throw new Error("destructuredLocals["+Q+"] is not a valid JS identifier.");if(Q>0)G+=`,
|
|
23
|
+
`;G+=A+" = __locals."+A}Y+=G+`;
|
|
24
|
+
`}if(g._with!==!1)Y+=" with ("+g.localsName+` || {}) {
|
|
25
|
+
`,Z+=` }
|
|
26
|
+
`;Z+=` return __output;
|
|
27
|
+
`,this.source=Y+this.source+Z}if(g.compileDebug)f=`var __line = 1
|
|
28
|
+
, __lines = `+JSON.stringify(this.templateText)+`
|
|
29
|
+
, __filename = `+V+`;
|
|
30
|
+
try {
|
|
31
|
+
`+this.source+`} catch (e) {
|
|
32
|
+
rethrow(e, __lines, __filename, __line, escapeFn);
|
|
33
|
+
}
|
|
34
|
+
`;else f=this.source;if(g.client){if(f="escapeFn = escapeFn || "+$.toString()+`;
|
|
35
|
+
`+f,g.compileDebug)f="rethrow = rethrow || "+Q1.toString()+`;
|
|
36
|
+
`+f}if(g.strict)f=`"use strict";
|
|
37
|
+
`+f;if(g.debug)console.log(f);if(g.compileDebug&&g.filename)f=f+`
|
|
38
|
+
//# sourceURL=`+V+`
|
|
39
|
+
`;try{if(g.async)try{J=new Function("return (async function(){}).constructor;")()}catch(w){if(w instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw w}else J=Function;z=new J(g.localsName+", escapeFn, include, rethrow",f)}catch(w){if(w instanceof SyntaxError){if(g.filename)w.message+=" in "+g.filename;if(w.message+=` while compiling ejs
|
|
40
|
+
|
|
41
|
+
`,w.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
|
+
`,w.message+="https://github.com/RyanZim/EJS-Lint",!g.async)w.message+=`
|
|
43
|
+
`,w.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw w}var j=g.client?z:function w(H){var D=function(v1,c){var S=B.shallowCopy(B.createNullProtoObjWherePossible(),H);if(c)S=B.shallowCopy(S,c);return z0(v1,g)(S)};return z.apply(g.context,[H||B.createNullProtoObjWherePossible(),$,D,Q1])};if(g.filename&&typeof Object.defineProperty==="function"){var X=g.filename,W=K.basename(X,K.extname(X));try{Object.defineProperty(j,"name",{value:W,writable:!1,enumerable:!1,configurable:!0})}catch(w){}}return j},generateSource:function(){var f=this.opts;if(f.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
|
+
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var z=this,g=this.parseTemplateText(),Y=this.opts.delimiter,Z=this.opts.openDelimiter,$=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(J,V){var G;if(J.indexOf(Z+Y)===0&&J.indexOf(Z+Y+Y)!==0){if(G=g[V+2],!(G==Y+$||G=="-"+Y+$||G=="_"+Y+$))throw new Error('Could not find matching close tag for "'+J+'".')}z.scanLine(J)})},parseTemplateText:function(){var f=this.templateText,z=this.regex,g=z.exec(f),Y=[],Z;while(g){if(Z=g.index,Z!==0)Y.push(f.substring(0,Z)),f=f.slice(Z);Y.push(g[0]),f=f.slice(g[0].length),g=z.exec(f)}if(f)Y.push(f);return Y},_addOutput:function(f){if(this.truncate)f=f.replace(/^(?:\r\n|\r|\n)/,""),this.truncate=!1;if(!f)return f;f=f.replace(/\\/g,"\\\\"),f=f.replace(/\n/g,"\\n"),f=f.replace(/\r/g,"\\r"),f=f.replace(/"/g,"\\\""),this.source+=' ; __append("'+f+`")
|
|
45
|
+
`},scanLine:function(f){var z=this,g=this.opts.delimiter,Y=this.opts.openDelimiter,Z=this.opts.closeDelimiter,$=0;switch($=f.split(`
|
|
46
|
+
`).length-1,f){case Y+g:case Y+g+"_":this.mode=C.modes.EVAL;break;case Y+g+"=":this.mode=C.modes.ESCAPED;break;case Y+g+"-":this.mode=C.modes.RAW;break;case Y+g+"#":this.mode=C.modes.COMMENT;break;case Y+g+g:this.mode=C.modes.LITERAL,this.source+=' ; __append("'+f.replace(Y+g+g,Y+g)+`")
|
|
47
|
+
`;break;case g+g+Z:this.mode=C.modes.LITERAL,this.source+=' ; __append("'+f.replace(g+g+Z,g+Z)+`")
|
|
48
|
+
`;break;case g+Z:case"-"+g+Z:case"_"+g+Z:if(this.mode==C.modes.LITERAL)this._addOutput(f);this.mode=null,this.truncate=f.indexOf("-")===0||f.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case C.modes.EVAL:case C.modes.ESCAPED:case C.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
|
|
49
|
+
`))f+=`
|
|
50
|
+
`}switch(this.mode){case C.modes.EVAL:this.source+=" ; "+f+`
|
|
51
|
+
`;break;case C.modes.ESCAPED:this.source+=" ; __append(escapeFn("+W1(f)+`))
|
|
52
|
+
`;break;case C.modes.RAW:this.source+=" ; __append("+W1(f)+`)
|
|
53
|
+
`;break;case C.modes.COMMENT:break;case C.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(z.opts.compileDebug&&$)this.currentLine+=$,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
+
`}};w1.escapeXML=B.escapeXML;w1.__express=w1.renderFile;w1.VERSION=l1;w1.name=a1;if(typeof window!="undefined")window.ejs=w1});function v(f){switch(f.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 I=null;async function G0(){if(!I){let f=await Promise.resolve().then(() => D1(N1(),1));I=f.default||f}return I}var Q0={string:"text/plain; charset=utf-8",object:"application/json; charset=utf-8",Uint8Array:"application/octet-stream",ArrayBuffer:"application/octet-stream"};function k(f,z,g,Y){let Z=null,$=null,J=null,V=null,G={},Q=null;return{req:f,server:z,pathname:g,status:200,headers:new Headers,setHeader(A,j){return this.headers.set(A,j),this},removeHeader(A){return this.headers.delete(A),this},set(A,j){return G[A]=j,this},get(A){return G[A]},get ip(){return this.server.requestIP(f)?.address??null},get url(){if(!Q)Q=new URL(f.url);return Q},get query(){if(!Z){if(!this.url.search)return{};Z=Object.fromEntries(this.url.searchParams)}return Z},get params(){if(!$&&Y)try{$=B0(Y,g)}catch(A){let j=A instanceof Error?A.message:String(A);throw new Error(`Failed to extract route parameters: ${j}`)}return $??{}},get body(){if(f.method==="GET")return Promise.resolve({});if(!V)V=(async()=>{try{let A=await C0(f);if(A.error)throw new Error(A.error);return Object.keys(A).length===0?null:A}catch(A){throw new Error("Invalid request body format")}})();return V},text(A,j=200){if(this.status=j,!this.headers.has("Content-Type"))this.headers.set("Content-Type","text/plain; charset=utf-8");return new Response(A,{status:j,headers:this.headers})},send(A,j=200){this.status=j;let X;if(A instanceof Uint8Array)X="Uint8Array";else if(A instanceof ArrayBuffer)X="ArrayBuffer";else X=typeof A;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",Q0[X]??"text/plain; charset=utf-8");let W=X==="object"&&A!==null?JSON.stringify(A):A;return new Response(W,{status:j,headers:this.headers})},json(A,j=200){if(this.status=j,!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return Response.json(A,{status:j,headers:this.headers})},file(A,j,X=200){this.status=X;let W=Bun.file(A);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",j??v(A));return new Response(W,{status:X,headers:this.headers})},async ejs(A,j={},X=200){this.status=X;let W=await G0();try{let w=await Bun.file(A).text(),H=W.render(w,j),D=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(H,{status:X,headers:D})}catch(w){return console.error("EJS Rendering Error:",w),new Response("Error rendering template",{status:500})}},redirect(A,j=302){return this.status=j,this.headers.set("Location",A),new Response(null,{status:j,headers:this.headers})},stream(A){let j=new Headers(this.headers),X=new ReadableStream({async start(W){await A(W),W.close()}});return new Response(X,{headers:j})},yieldStream(A){return new Response("not working stream yet.")},setCookie(A,j,X={}){let W=`${encodeURIComponent(A)}=${encodeURIComponent(j)}`;if(X.maxAge)W+=`; Max-Age=${X.maxAge}`;if(X.expires)W+=`; Expires=${X.expires.toUTCString()}`;if(X.path)W+=`; Path=${X.path}`;if(X.domain)W+=`; Domain=${X.domain}`;if(X.secure)W+="; Secure";if(X.httpOnly)W+="; HttpOnly";if(X.sameSite)W+=`; SameSite=${X.sameSite}`;return this.headers.append("Set-Cookie",W),this},get cookies(){if(!J){let A=this.req.headers.get("cookie");J=A?W0(A):{}}return J}}}function W0(f){return Object.fromEntries(f.split(";").map((z)=>{let[g,...Y]=z.trim().split("=");return[g,decodeURIComponent(Y.join("="))]}))}function B0(f,z){let g={},Y=f.split("/"),[Z]=z.split("?"),$=Z.split("/");if(Y.length!==$.length)return null;for(let J=0;J<Y.length;J++){let V=Y[J];if(V.charCodeAt(0)===58)g[V.slice(1)]=$[J]}return g}async function C0(f){let z=f.headers.get("Content-Type")||"";if(!z)return{};if(f.headers.get("Content-Length")==="0"||!f.body)return{};if(z.startsWith("application/json"))return await f.json();if(z.startsWith("application/x-www-form-urlencoded")){let Y=await f.text();return Object.fromEntries(new URLSearchParams(Y))}if(z.startsWith("multipart/form-data")){let Y=await f.formData(),Z={};for(let[$,J]of Y.entries())Z[$]=J;return Z}return{error:"Unknown request body type"}}var w0=(f,z)=>{try{return z(f)}catch{return f.replace(/(?:%[0-9A-Fa-f]{2})+/g,(g)=>{try{return z(g)}catch{return g}})}},y=(f)=>w0(f,decodeURI),T0=(f)=>{let z=f.indexOf("/",f.indexOf(":")+4),g=z;for(;g<f.length;g++){let Y=f.charCodeAt(g);if(Y===37){let Z=f.indexOf("?",g),$=f.slice(z,Z===-1?void 0:Z);return y($.includes("%25")?$.replace(/%25/g,"%2525"):$)}else if(Y===63)break}return f.slice(z,g)};async function U0(f,z,g){let Y,Z=f.url.indexOf("/",f.url.indexOf(":")+4),$=Z;for(;$<f.url.length;$++){let A=f.url.charCodeAt($);if(A===37){let j=f.url.indexOf("?",$),X=f.url.slice(Z,j===-1?void 0:j);Y=y(X.includes("%25")?X.replace(/%25/g,"%2525"):X);break}else if(A===63)break}if(!Y)Y=f.url.slice(Z,$);let J=g.trie.search(Y,f.method),V=k(f,z,Y,J?.path);if(g.hasOnReqHook)await x("onRequest",g.hooks.onRequest,[f,Y,z]);if(g.hasMiddleware){let A=await M0(g,Y,V);if(A)return A}if(g.hasFilterEnabled){let A=await K0(g,Y,V);if(A)return A}if(!J)return await H0(g,V,Y);if(g.hasPreHandlerHook){let A=await x("preHandler",g.hooks.preHandler,[V]);if(A)return A}let G=J.handler(V),Q=G instanceof Promise?await G:G;if(g.hasOnSendHook){let A=await x("onSend",g.hooks.onSend,[V,Q]);if(A)return A}if(Q instanceof Response)return Q;return H1(500,"No response returned from handler.")}async function x(f,z,g){if(!z?.length)return;for(let Y=0;Y<z.length;Y++){let Z=z[Y](...g),$=Z instanceof Promise?await Z:Z;if($&&f!=="onRequest")return $}}async function M0(f,z,g){let Y=f.globalMiddlewares;if(Y.length)for(let $ of Y){let J=await $(g);if(J)return J}let Z=f.middlewares.get(z);if(Z&&Z.length)for(let $ of Z){let J=await $(g);if(J)return J}return null}async function c0(f,z,g){for(let Y of f){let Z=await Y(z,g);if(Z)return Z}}async function K0(f,z,g){let Y=await N0(f,z,g),Z=Y instanceof Promise?await Y:Y;if(Z)return Z}async function N0(f,z,g){if(z.endsWith("/"))z=z.slice(0,-1);if(!f.filters.has(z))if(f.filterFunction.length)for(let Y of f.filterFunction){let Z=await Y(g);if(Z)return Z}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function m0(f,z,g,Y){if(!f.filters.has(z))if(f.filterFunction.length)for(let Z of f.filterFunction){let $=await Z(g,Y);if($)return $}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function H0(f,z,g){if(f.staticPath){let Z=await v0(f,g,z);if(Z)return Z;let $=f.trie.search("*",z.req.method);if($?.handler)return await $.handler(z)}return f.routeNotFoundFunc(z)||H1(404,`Route not found for ${g}`)}function H1(f,z){return new Response(JSON.stringify({error:z}),{status:f,headers:{"Content-Type":"application/json"}})}async function v0(f,z,g){if(!f.staticPath)return null;let Y=`${f.staticPath}${z}`;if(await Bun.file(Y).exists()){let $=v(Y);return g.file(Y,$,200)}return null}export{M0 as runMiddlewares,x as runHooks,K0 as runFilter,v0 as handleStaticFiles,H0 as handleRouteNotFound,N0 as handleFilterRequest,m0 as handleBunFilterRequest,H1 as generateErrorResponse,c0 as executeBunMiddlewares,U0 as default};
|
package/dist/main.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export default class Diesel {
|
|
|
10
10
|
globalMiddlewares: middlewareFunc[];
|
|
11
11
|
middlewares: Map<string, middlewareFunc[]>;
|
|
12
12
|
trie: Trie;
|
|
13
|
+
hasOnReqHook: boolean;
|
|
14
|
+
hasMiddleware: boolean;
|
|
15
|
+
hasPreHandlerHook: boolean;
|
|
16
|
+
hasPostHandlerHook: boolean;
|
|
17
|
+
hasOnSendHook: boolean;
|
|
18
|
+
hasOnError: boolean;
|
|
13
19
|
hooks: Hooks;
|
|
14
20
|
corsConfig: corsT;
|
|
15
21
|
FilterRoutes: string[] | null | undefined;
|
package/dist/main.js
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
var c=Object.create;var{getPrototypeOf:k,defineProperty:R,getOwnPropertyNames:u}=Object;var x=Object.prototype.hasOwnProperty;var i=(g,f,L)=>{L=g!=null?c(k(g)):{};let $=f||!g||!g.__esModule?R(L,"default",{value:g,enumerable:!0}):L;for(let A of u(g))if(!x.call($,A))R($,A,{get:()=>g[A],enumerable:!0});return $};var o=((g)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(g,{get:(f,L)=>(typeof require!=="undefined"?require:f)[L]}):g)(function(g){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+g+'" is not supported')});class Q{children;isEndOfWord;handler;isDynamic;pattern;path;method;constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[]}}class D{root;constructor(){this.root=new Q}insert(g,f){let L=this.root,$=g.split("/").filter(Boolean);if(g==="/"){L.isEndOfWord=!0,L.handler.push(f.handler),L.path=g,L.method.push(f.method);return}for(let A of $){let C=!1,E=A;if(A.startsWith(":"))C=!0,E=":";if(!L.children[E])L.children[E]=new Q;L=L.children[E],L.isDynamic=C,L.pattern=A}L.isEndOfWord=!0,L.path=g,L.method.push(f.method),L.handler.push(f.handler)}search(g,f){let L=this.root,$=g.split("/").filter(Boolean),A=$.length;for(let G of $){let v=G;if(!L.children[v])if(L.children[":"])L=L.children[":"];else return null;else L=L.children[v]}let C=L.path.split("/").filter(Boolean);if(A!==C.length)return null;let E=L.method.indexOf(f);if(E!==-1)return{path:L.path,handler:L.handler[E],isDynamic:L.isDynamic,pattern:L.pattern,method:L.method[E]};return null}}function W(g){switch(g.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"}}function I(g,f,L){let $=null,A=null,C=null,E=null,G={};return{req:g,server:f,url:L,status:200,headers:new Headers,setHeader(v,S){return this.headers.set(v,S),this},removeHeader(v){return this.headers.delete(v),this},get ip(){return this.server.requestIP(this.req)?.address??null},get query(){if(!$)try{$=Object.fromEntries(this.url.searchParams)}catch(v){throw new Error("Failed to parse query parameters")}return $},get params(){if(!A&&this.req.routePattern)try{A=s(this.req.routePattern,this.url.pathname)}catch(v){throw new Error("Failed to extract route parameters")}return A??{}},get body(){if(this.req.method==="GET")return Promise.resolve({});if(!E)E=(async()=>{let v=await r(this.req);if(v.error)throw new Error(v.error);return Object.keys(v).length===0?null:v})();return E},set(v,S){return G[v]=S,this},get(v){return G[v]},text(v,S){if(S)this.status=S;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type","text/plain; charset=utf-8");return new Response(v,{status:this.status,headers:this.headers})},send(v,S){if(S)this.status=S;let U=new Map([["string","text/plain; charset=utf-8"],["object","application/json; charset=utf-8"],["Uint8Array","application/octet-stream"],["ArrayBuffer","application/octet-stream"]]),K;if(v instanceof Uint8Array)K="Uint8Array";else if(v instanceof ArrayBuffer)K="ArrayBuffer";else K=typeof v;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",U.get(K)??"text/plain; charset=utf-8");let Z=K==="object"&&v!==null?JSON.stringify(v):v;return new Response(Z,{status:this.status,headers:this.headers})},json(v,S){if(S)this.status=S;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return Response.json(v,{status:this.status,headers:this.headers})},file(v,S,U){if(U)this.status=U;let K=Bun.file(v);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",S??W(v));return new Response(K,{status:this.status,headers:this.headers})},async ejs(v,S={},U){if(U)this.status=U;let K;try{K=await import("ejs"),K=K.default||K}catch(Z){return console.error("EJS not installed! Please run `bun add ejs`"),new Response("EJS not installed! Please run `bun add ejs`",{status:500})}try{let Z=await Bun.file(v).text(),z=K.render(Z,S),P=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(z,{status:this.status,headers:P})}catch(Z){return console.error("EJS Rendering Error:",Z),new Response("Error rendering template",{status:500})}},redirect(v,S){if(S)this.status=S;else this.status=302;return this.headers.set("Location",v),new Response(null,{status:this.status,headers:this.headers})},stream(v){let S=new Headers(this.headers),U=new ReadableStream({async start(K){await v(K),K.close()}});return new Response(U,{headers:S})},yieldStream(v){return new Response({async*[Symbol.asyncIterator](){yield*v()}},{headers:this.headers})},setCookie(v,S,U={}){let K=`${encodeURIComponent(v)}=${encodeURIComponent(S)}`;if(U.maxAge)K+=`; Max-Age=${U.maxAge}`;if(U.expires)K+=`; Expires=${U.expires.toUTCString()}`;if(U.path)K+=`; Path=${U.path}`;if(U.domain)K+=`; Domain=${U.domain}`;if(U.secure)K+="; Secure";if(U.httpOnly)K+="; HttpOnly";if(U.sameSite)K+=`; SameSite=${U.sameSite}`;return this.headers.append("Set-Cookie",K),this},get cookies(){if(!C){let v=this.req.headers.get("cookie");C=v?l(v):{}}return C}}}function l(g){return Object.fromEntries(g.split(";").map((f)=>{let[L,...$]=f.trim().split("=");return[L,decodeURIComponent($.join("="))]}))}function s(g,f){let L={},$=g.split("/"),[A]=f.split("?"),C=A.split("/");if($.length!==C.length)return null;for(let E=0;E<$.length;E++)if($[E].startsWith(":"))L[$[E].slice(1)]=C[E];return L}async function r(g){let f=g.headers.get("Content-Type");if(!f)return{};if(g.headers.get("Content-Length")==="0"||!g.body)return{};try{if(f.startsWith("application/json"))return await g.json();if(f.startsWith("application/x-www-form-urlencoded")){let $=await g.text();return Object.fromEntries(new URLSearchParams($))}if(f.startsWith("multipart/form-data")){let $=await g.formData(),A={};for(let[C,E]of $.entries())A[C]=E;return A}return{error:"Unknown request body type"}}catch($){return{error:"Invalid request body format"}}}async function F(g,f,L,$){let A=I(g,f,L),C=$.trie.search(L.pathname,g.method);g.routePattern=C?.path;try{if($.hooks.onRequest)await J("onRequest",$.hooks.onRequest,[g,L,f]);if($.hasMiddleware){let v=await p($,L.pathname,A,f);if(v)return v}if($.hasFilterEnabled){let v=g.routePattern??L.pathname,S=await d($,v,A,f);if(S)return S}if(!C)return await t($,A,L.pathname);if($.hooks.preHandler){let v=await J("preHandler",$.hooks.preHandler,[A,f]);if(v)return v}let E=C.handler(A),G=E instanceof Promise?await E:E;if($.hasOnSendHook){let v=await J("onSend",$.hooks.onSend,[A,G,f]);if(v)return v}if(G instanceof Response)return G;return B(500,"No response returned from handler.")}catch(E){return await J("onError",$.hooks.onError,[E,g,L,f])||B(500,"Internal Server Error")}}async function J(g,f,L){if(!f?.length)return;for(let $=0;$<f.length;$++){let A=f[$](...L),C=A instanceof Promise?await A:A;if(C&&g!=="onRequest")return C}}async function p(g,f,L,$){if(g.globalMiddlewares.length){let C=await H(g.globalMiddlewares,L,$);if(C)return C}let A=g.middlewares.get(f)||[];if(A.length){let C=await H(A,L,$);if(C)return C}return null}async function H(g,f,L){for(let $ of g){let A=await $(f,L);if(A)return A}return null}async function _(g,f,L){for(let $ of g){let A=await $(f,L);if(A)return A}}async function d(g,f,L,$){let A=await h(g,f,L,$),C=A instanceof Promise?await A:A;if(C)return C}async function h(g,f,L,$){if(f.endsWith("/"))f=f.slice(0,-1);if(!g.filters.has(f))if(g.filterFunction.length)for(let A of g.filterFunction){let C=await A(L,$);if(C)return C}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function J1(g,f,L,$){if(!g.filters.has(f))if(g.filterFunction.length)for(let A of g.filterFunction){let C=await A(L,$);if(C)return C}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function t(g,f,L){if(g.staticPath){let A=await a(g,L,f);if(A)return A;let C=g.trie.search("*",f.req.method);if(C?.handler)return await C.handler(f)}return g.routeNotFoundFunc(f)||B(404,`Route not found for ${L}`)}function B(g,f){return new Response(JSON.stringify({error:f}),{status:g,headers:{"Content-Type":"application/json"}})}async function a(g,f,L){if(!g.staticPath)return null;let $=`${g.staticPath}${f}`;if(await Bun.file($).exists()){let C=W($);return L.file($,C,200)}return null}function Y(g){if(typeof g!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(g))}function M(g,f){var L="",$=0,A=-1,C=0,E;for(var G=0;G<=g.length;++G){if(G<g.length)E=g.charCodeAt(G);else if(E===47)break;else E=47;if(E===47){if(A===G-1||C===1);else if(A!==G-1&&C===2){if(L.length<2||$!==2||L.charCodeAt(L.length-1)!==46||L.charCodeAt(L.length-2)!==46){if(L.length>2){var v=L.lastIndexOf("/");if(v!==L.length-1){if(v===-1)L="",$=0;else L=L.slice(0,v),$=L.length-1-L.lastIndexOf("/");A=G,C=0;continue}}else if(L.length===2||L.length===1){L="",$=0,A=G,C=0;continue}}if(f){if(L.length>0)L+="/..";else L="..";$=2}}else{if(L.length>0)L+="/"+g.slice(A+1,G);else L=g.slice(A+1,G);$=G-A-1}A=G,C=0}else if(E===46&&C!==-1)++C;else C=-1}return L}function e(g,f){var L=f.dir||f.root,$=f.base||(f.name||"")+(f.ext||"");if(!L)return $;if(L===f.root)return L+$;return L+g+$}function N(){var g="",f=!1,L;for(var $=arguments.length-1;$>=-1&&!f;$--){var A;if($>=0)A=arguments[$];else{if(L===void 0)L=process.cwd();A=L}if(Y(A),A.length===0)continue;g=A+"/"+g,f=A.charCodeAt(0)===47}if(g=M(g,!f),f)if(g.length>0)return"/"+g;else return"/";else if(g.length>0)return g;else return"."}function j(g){if(Y(g),g.length===0)return".";var f=g.charCodeAt(0)===47,L=g.charCodeAt(g.length-1)===47;if(g=M(g,!f),g.length===0&&!f)g=".";if(g.length>0&&L)g+="/";if(f)return"/"+g;return g}function g1(g){return Y(g),g.length>0&&g.charCodeAt(0)===47}function f1(){if(arguments.length===0)return".";var g;for(var f=0;f<arguments.length;++f){var L=arguments[f];if(Y(L),L.length>0)if(g===void 0)g=L;else g+="/"+L}if(g===void 0)return".";return j(g)}function L1(g,f){if(Y(g),Y(f),g===f)return"";if(g=N(g),f=N(f),g===f)return"";var L=1;for(;L<g.length;++L)if(g.charCodeAt(L)!==47)break;var $=g.length,A=$-L,C=1;for(;C<f.length;++C)if(f.charCodeAt(C)!==47)break;var E=f.length,G=E-C,v=A<G?A:G,S=-1,U=0;for(;U<=v;++U){if(U===v){if(G>v){if(f.charCodeAt(C+U)===47)return f.slice(C+U+1);else if(U===0)return f.slice(C+U)}else if(A>v){if(g.charCodeAt(L+U)===47)S=U;else if(U===0)S=0}break}var K=g.charCodeAt(L+U),Z=f.charCodeAt(C+U);if(K!==Z)break;else if(K===47)S=U}var z="";for(U=L+S+1;U<=$;++U)if(U===$||g.charCodeAt(U)===47)if(z.length===0)z+="..";else z+="/..";if(z.length>0)return z+f.slice(C+S);else{if(C+=S,f.charCodeAt(C)===47)++C;return f.slice(C)}}function $1(g){return g}function C1(g){if(Y(g),g.length===0)return".";var f=g.charCodeAt(0),L=f===47,$=-1,A=!0;for(var C=g.length-1;C>=1;--C)if(f=g.charCodeAt(C),f===47){if(!A){$=C;break}}else A=!1;if($===-1)return L?"/":".";if(L&&$===1)return"//";return g.slice(0,$)}function A1(g,f){if(f!==void 0&&typeof f!=="string")throw new TypeError('"ext" argument must be a string');Y(g);var L=0,$=-1,A=!0,C;if(f!==void 0&&f.length>0&&f.length<=g.length){if(f.length===g.length&&f===g)return"";var E=f.length-1,G=-1;for(C=g.length-1;C>=0;--C){var v=g.charCodeAt(C);if(v===47){if(!A){L=C+1;break}}else{if(G===-1)A=!1,G=C+1;if(E>=0)if(v===f.charCodeAt(E)){if(--E===-1)$=C}else E=-1,$=G}}if(L===$)$=G;else if($===-1)$=g.length;return g.slice(L,$)}else{for(C=g.length-1;C>=0;--C)if(g.charCodeAt(C)===47){if(!A){L=C+1;break}}else if($===-1)A=!1,$=C+1;if($===-1)return"";return g.slice(L,$)}}function E1(g){Y(g);var f=-1,L=0,$=-1,A=!0,C=0;for(var E=g.length-1;E>=0;--E){var G=g.charCodeAt(E);if(G===47){if(!A){L=E+1;break}continue}if($===-1)A=!1,$=E+1;if(G===46){if(f===-1)f=E;else if(C!==1)C=1}else if(f!==-1)C=-1}if(f===-1||$===-1||C===0||C===1&&f===$-1&&f===L+1)return"";return g.slice(f,$)}function v1(g){if(g===null||typeof g!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof g);return e("/",g)}function G1(g){Y(g);var f={root:"",dir:"",base:"",ext:"",name:""};if(g.length===0)return f;var L=g.charCodeAt(0),$=L===47,A;if($)f.root="/",A=1;else A=0;var C=-1,E=0,G=-1,v=!0,S=g.length-1,U=0;for(;S>=A;--S){if(L=g.charCodeAt(S),L===47){if(!v){E=S+1;break}continue}if(G===-1)v=!1,G=S+1;if(L===46){if(C===-1)C=S;else if(U!==1)U=1}else if(C!==-1)U=-1}if(C===-1||G===-1||U===0||U===1&&C===G-1&&C===E+1){if(G!==-1)if(E===0&&$)f.base=f.name=g.slice(1,G);else f.base=f.name=g.slice(E,G)}else{if(E===0&&$)f.name=g.slice(1,C),f.base=g.slice(1,G);else f.name=g.slice(E,C),f.base=g.slice(E,G);f.ext=g.slice(C,G)}if(E>0)f.dir=g.slice(0,E-1);else if($)f.dir="/";return f}var S1="/",U1=":",K1=((g)=>(g.posix=g,g))({resolve:N,normalize:j,isAbsolute:g1,join:f1,relative:L1,_makeLong:$1,dirname:C1,basename:A1,extname:E1,format:v1,parse:G1,sep:S1,delimiter:U1,win32:null,posix:null}),V=K1;var{default:b}=(()=>({}));var X={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"}},T=(g,f,L)=>{let $=X[g]||X.reset,A=L?.method?X.method[L.method]||X.reset:X.reset,C=L?.status?L.status>=500?X.error:L.status>=400?X.warn:X.info:X.reset;console.log(`
|
|
2
|
-
|
|
3
|
-
`)},q=(g)=>{let{app:f,logger:L,logLevel:$="info",onRequest:A,onSend:C,onError:E}=g||{};f?.addHooks("onRequest",(G,v)=>{G.startTime=Date.now(),L?.()??T($,"Incoming Request",{method:G.method,url:v.toString(),headers:{"user-agent":G.headers.get("user-agent"),"content-type":G.headers.get("content-type")}}),A?.(G,v)}),f?.addHooks("onSend",async(G)=>{let v=`${Date.now()-G.req.startTime}ms`;L?.()??T($,"Response Sent",{method:G.req.method,url:G.url.toString(),status:G.status,duration:v,reqId:G.get?.("requestId"),headers:{"content-type":G.headers.get("content-type")}});let S=await C?.(G);if(S instanceof Response)return S}),f?.addHooks("onError",async(G,v,S)=>{L?.()??T("error","Unhandled Error",{method:v.method,url:S.toString(),status:500,error:G.message});let U=await E?.(G,v,S);if(U instanceof Response)return U})},O=(g,f,L,$=0,A,C)=>{let E=X.method[f]||X.reset,G=$>=500?X.error:$>=400?X.warn:X.info,v=C?`[${C}] `:"",S=g==="<--"?`${g} ${E}${f}${X.reset} ${L} ${v}`:`${g} ${E}${f}${X.reset} ${L} ${G}${$}${X.reset} ${A??""} ${v}`;console.log(S)},X1=(g)=>{let f=Date.now()-g;return f<1000?`${f}ms`:`${Math.round(f/1000)}s`},y=(g)=>{let{app:f,log:L,onRequest:$,onSend:A,onError:C}=g;f.addHooks("onRequest",(E,G)=>{E.startTime=Date.now(),L?.()??O("<--",E.method,G.pathname),$?.(E,G)}),f.addHooks("onSend",async(E)=>{let{method:G,url:v}=E.req,S=new URL(v).pathname,U=E.get?.("requestId");L?.()??O("-->",G,S,E.status,X1(E.req.startTime),U);let K=await A?.(E);if(K instanceof Response)return K}),f.addHooks("onError",async(E,G,v)=>{L?.()??O(E.message,G.method,v.toString(),500);let S=await C?.(E,G,v);if(S instanceof Response)return S})};function w(g,f){if(!g)throw new Error("JWT library is not defined, please provide jwt to authenticateJwt Function");return(L)=>{try{let $=L.cookies?.accessToken??L.req?.headers?.get("Authorization");if(!$)return L.json({message:"Unauthorized",error:"No token provided"},401);if($.startsWith("Bearer "))$=$.slice(7);let A=g?.verify($,f);if(!A)return L.json({message:"Unauthorized",error:"Token could not be decoded"},401);L.set("user",A)}catch($){let A="Invalid token";if($.name==="TokenExpiredError")A="Token expired";else if($.name==="JsonWebTokenError")A="Malformed or tampered token";return L.json({message:"Unauthorized",error:A},401)}}}function m(g,f,L){if(!g)throw new Error("JWT library is not defined, please provide jwt to authenticateJwtDB Function");if(!f)throw new Error("User model is not defined, please provide UserModel to authenticateJwtDB Function");return async($)=>{try{let A=$.cookies?.accessToken??$.req?.headers?.get("Authorization");if(!A)return $.json({message:"Unauthorized",error:"No token provided"},401);if(A.startsWith("Bearer "))A=A.slice(7);let C=g?.verify(A,L);if(!C)return $.json({message:"Unauthorized",error:"Token could not be decoded"},401);let E=await f.findById(C._id).select("-password -refreshToken");if(!E)return $.json({message:"Unauthorized: User not found"},404);$.set("user",E);return}catch(A){let C="Invalid token";if(A.name==="TokenExpiredError")C="Token expired";else if(A.name==="JsonWebTokenError")C="Malformed or tampered token";return $.json({message:"Unauthorized",error:C},401)}}}class n{static instance;fecth;routes;tempRoutes;globalMiddlewares;middlewares;trie;hasOnReqHook;hasMiddleware;hasPreHandlerHook;hasPostHandlerHook;hasOnSendHook;hasOnError;hooks;corsConfig;FilterRoutes;filters;filterFunction;hasFilterEnabled;serverInstance;staticPath;staticFiles;user_jwt_secret;baseApiUrl;enableFileRouter;idleTimeOut;routeNotFoundFunc;prefixApiUrl;constructor({jwtSecret:g,baseApiUrl:f,enableFileRouting:L,idleTimeOut:$,prefixApiUrl:A}={}){if(!n.instance)n.instance=this;this.prefixApiUrl=A??"",this.fetch=this.fetch.bind(this),this.routes={},this.idleTimeOut=$??10,this.enableFileRouter=L??!1,this.baseApiUrl=f||"",this.user_jwt_secret=g||process.env.DIESEL_JWT_SECRET||"feault_diesel_secret_for_jwt",this.tempRoutes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new D,this.corsConfig=null,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hasOnError=!1,this.hooks={onRequest:[],preHandler:[],postHandler:[],onSend:[],onError:[],onClose:[]},this.FilterRoutes=[],this.filters=new Set,this.filterFunction=[],this.hasFilterEnabled=!1,this.serverInstance=null,this.staticPath=null,this.staticFiles={},this.routeNotFoundFunc=()=>{}}static router(g){if(!this.instance)console.log("no instance"),this.instance=new n;return new Proxy(this.instance,{get(f,L,$){return(A,C)=>{let E=g+A;return f[L](E,C)}}})}setupFilter(){return this.hasFilterEnabled=!0,{publicRoutes:(...g)=>{return this.FilterRoutes=g,this.setupFilter()},permitAll:()=>{for(let g of this?.FilterRoutes){if(g.endsWith("/"))g=g.slice(0,-1);this.filters.add(g)}return this.FilterRoutes=null,this.setupFilter()},authenticate:(g)=>{if(g?.length)for(let f of g)this.filterFunction.push(f)},authenticateJwt:(g)=>{this.filterFunction.push(w(g,this.user_jwt_secret))},authenticateJwtDB:(g,f)=>{this.filterFunction.push(m(g,f,this.user_jwt_secret))}}}redirect(g,f,L){return this.any(g,($)=>{let A=$.params,C=f;if(A)for(let G in A)C=C.replace(`:${G}`,A[G]);let E=$.url.search;if(E)C+=E;return $.redirect(C,L)}),this}serveStatic(g){return this.staticPath=g,this}static(g){return this.staticPath=g,this}staticHtml(g){return this.staticFiles={...this.staticFiles,...g},this}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");switch(g){case"onRequest":this.hooks.onRequest?.push(f);break;case"preHandler":this.hooks.preHandler?.push(f);break;case"postHandler":this.hooks.postHandler?.push(f);break;case"onSend":this.hooks.onSend?.push(f);break;case"onError":this.hooks.onError?.push(f);break;case"onClose":this.hooks.onClose?.push(f);break;default:throw new Error(`Unknown hook type: ${g}`)}return this}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?.enableFileRouter){let g=process.cwd(),f=V.join(g,"src","routes");if(b?.existsSync(f))this.loadRoutes(f,"")}setTimeout(()=>{this.tempRoutes=null},2000)}async registerFileRoutes(g,f,L){let $=await import(g),A;if(L===".ts")A=V.basename(g,".ts");else if(L===".js")A=V.basename(g,".js");let C=f+"/"+A;if(C.endsWith("/index"))C=f;else if(C.endsWith("/api"))C=f;C=C.replace(/\[(.*?)\]/g,":$1");let E=["GET","POST","PUT","PATCH","DELETE","ANY","HEAD","OPTIONS","PROPFIND"];for(let G of E)if($[G]){let v=G.toLowerCase(),S=$[G];this[v](`${this.baseApiUrl}${C}`,S)}}async loadRoutes(g,f){let L=await b.promises.readdir(g);for(let $ of L){let A=V.join(g,$);if((await b.promises.stat(A)).isDirectory())await this.loadRoutes(A,f+"/"+$);else if($.endsWith(".ts"))await this.registerFileRoutes(A,f,".ts");else if($.endsWith(".js"))await this.registerFileRoutes(A,f,".js")}}useLogger(g){return y(g),this}useAdvancedLogger(g){return q(g),this}BunRoute(g,f,...L){if(!f||typeof f!=="string")throw new Error("give a path in string format");this.routes[f]=async($,A)=>{if(this.hasMiddleware){if(this.globalMiddlewares.length){let E=await _(this.globalMiddlewares,$,A);if(E)return E}let C=this.middlewares.get(f)||[];if(C?.length){let E=await _(C,$,A);if(E)return E}}if(g!==$.method)return new Response("Method Not Allowed",{status:405});if(L.length===1){let C=L[0]($,A);if(C instanceof Promise)return await C??new Response("Not Found",{status:404});if(C instanceof Response)return C}else for(let C=0;C<L.length;C++){let E=L[C]($,A);if(E instanceof Promise)return await E??new Response("Not Found",{status:404});if(E instanceof Response)return E}}}listen(g,...f){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");let L="0.0.0.0",$=void 0,A={};for(let E of f)if(typeof E==="string")L=E;else if(typeof E==="function")$=E;else if(typeof E==="object"&&E!==null)A=E;let C={port:g,hostname:L,idleTimeOut:this.idleTimeOut,fetch:this.fetch(),static:this.staticFiles};if(this.routes&&Object.keys(this.routes).length>0)C.routes=this.routes;if(A.cert&&A.key)C.certFile=A.cert,C.keyFile=A.key;if(this.serverInstance=Bun?.serve(C),$)$();return this.serverInstance}fetch(){return this.compile(),async(g,f)=>{let L=new URL(g.url);return F(g,f,L,this)}}close(g){if(this.serverInstance)this.serverInstance.stop(!0),this.serverInstance=null,g?g():console.log("Server has been stopped");else console.warn("Server is not running.")}route(g,f){g=g&&g.length>0?g:f?.prefixApiUrl;let L=f?.tempRoutes??new Map;for(let[$,A]of L.entries()){let C=$.replace(/::\w+$/,""),E=`${g}${C}`;if(!this.middlewares.has(E))this.middlewares.set(E,[]);A.handlers.slice(0,-1).forEach((U)=>{let K=this.middlewares.get(E);if(!K.includes(U))K.push(U)});let v=A.handlers[A.handlers.length-1],S=A.method;try{this.trie.insert(E,{handler:v,method:S})}catch(U){console.error(`Error inserting ${E}:`,U)}}return f=null,this}register(g,f){return this.route(g,f)}addRoute(g,f,L){if(typeof f!=="string")throw new Error(`Error in ${L[L.length-1]}: Path must be a string. Received: ${typeof f}`);if(typeof g!=="string")throw new Error(`Error in addRoute: Method must be a string. Received: ${typeof g}`);this.tempRoutes?.set(f+"::"+g,{method:g,handlers:L});let $=L.slice(0,-1),A=L[L.length-1];if(!this.middlewares.has(f))this.middlewares.set(f,[]);$.forEach((C)=>{if(f==="/")this.globalMiddlewares=[...new Set([...this.globalMiddlewares,...$])];else if(!this.middlewares.get(f)?.includes(C))this.middlewares.get(f)?.push(C)});try{if(g==="ANY"){let C=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD","PROPFIND"];for(let E of C)this.trie.insert(f,{handler:A,method:E})}this.trie.insert(f,{handler:A,method:g})}catch(C){console.error(`Error inserting ${f}:`,C)}}use(g,f){if(Array.isArray(g))g.forEach(($)=>{if(typeof $==="function")this.globalMiddlewares.push($)});if(typeof g==="function"){if(this.globalMiddlewares.push(g),Array.isArray(f))f.forEach(($)=>{this.globalMiddlewares.push($)});return this}return(Array.isArray(g)?g.filter(($)=>typeof $==="string"):[g].filter(($)=>typeof $==="string")).forEach(($)=>{if(!this.middlewares.has($))this.middlewares.set($,[]);if(f)(Array.isArray(f)?f:[f]).forEach((C)=>{this.middlewares.get($)?.push(C)})}),this}get(g,...f){return this.addRoute("GET",g,f),this}post(g,...f){return this.addRoute("POST",g,f),this}put(g,...f){return this.addRoute("PUT",g,f),this}patch(g,...f){return this.addRoute("PATCH",g,f),this}delete(g,...f){return this.addRoute("DELETE",g,f),this}any(g,...f){return this.addRoute("ANY",g,f),this}head(g,...f){return this.addRoute("HEAD",g,f),this}options(g,...f){return this.addRoute("OPTIONS",g,f),this}propfind(g,...f){return this.addRoute("PROPFIND",g,f),this}routeNotFound(g){return this.routeNotFoundFunc=g,this}on(g,f,...L){let $=Array.isArray(g)?g:[g];for(let A of $){let C=A.toUpperCase();if(C.toLocaleLowerCase()in this)this[C.toLocaleLowerCase()](f,...L);else this.addRoute(C,f,L)}}}export{n as default};
|
|
1
|
+
var i1=Object.create;var{getPrototypeOf:d1,defineProperty:H,getOwnPropertyNames:L1,getOwnPropertyDescriptor:n1}=Object,Y1=Object.prototype.hasOwnProperty;var o1=($,L,C)=>{C=$!=null?i1(d1($)):{};let Y=L||!$||!$.__esModule?H(C,"default",{value:$,enumerable:!0}):C;for(let Z of L1($))if(!Y1.call(Y,Z))H(Y,Z,{get:()=>$[Z],enumerable:!0});return Y},C1=new WeakMap,r1=($)=>{var L=C1.get($),C;if(L)return L;if(L=H({},"__esModule",{value:!0}),$&&typeof $==="object"||typeof $==="function")L1($).map((Y)=>!Y1.call(L,Y)&&H(L,Y,{get:()=>$[Y],enumerable:!(C=n1($,Y))||C.enumerable}));return C1.set($,L),L},m=($,L)=>()=>(L||$((L={exports:{}}).exports,L),L.exports);var l1=($,L)=>{for(var C in L)H($,C,{get:L[C],enumerable:!0,configurable:!0,set:(Y)=>L[C]=()=>Y})};var p1=($,L)=>()=>($&&(L=$($=0)),L);var s1=(($)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy($,{get:(L,C)=>(typeof require!=="undefined"?require:L)[C]}):$)(function($){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+$+'" is not supported')});var E1={};l1(E1,{sep:()=>B1,resolve:()=>R,relative:()=>G1,posix:()=>v1,parse:()=>K1,normalize:()=>c,join:()=>z1,isAbsolute:()=>V1,format:()=>W1,extname:()=>A1,dirname:()=>J1,delimiter:()=>U1,default:()=>F,basename:()=>Q1,_makeLong:()=>X1});function D($){if(typeof $!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify($))}function Z1($,L){var C="",Y=0,Z=-1,V=0,z;for(var G=0;G<=$.length;++G){if(G<$.length)z=$.charCodeAt(G);else if(z===47)break;else z=47;if(z===47){if(Z===G-1||V===1);else if(Z!==G-1&&V===2){if(C.length<2||Y!==2||C.charCodeAt(C.length-1)!==46||C.charCodeAt(C.length-2)!==46){if(C.length>2){var J=C.lastIndexOf("/");if(J!==C.length-1){if(J===-1)C="",Y=0;else C=C.slice(0,J),Y=C.length-1-C.lastIndexOf("/");Z=G,V=0;continue}}else if(C.length===2||C.length===1){C="",Y=0,Z=G,V=0;continue}}if(L){if(C.length>0)C+="/..";else C="..";Y=2}}else{if(C.length>0)C+="/"+$.slice(Z+1,G);else C=$.slice(Z+1,G);Y=G-Z-1}Z=G,V=0}else if(z===46&&V!==-1)++V;else V=-1}return C}function a1($,L){var C=L.dir||L.root,Y=L.base||(L.name||"")+(L.ext||"");if(!C)return Y;if(C===L.root)return C+Y;return C+$+Y}function R(){var $="",L=!1,C;for(var Y=arguments.length-1;Y>=-1&&!L;Y--){var Z;if(Y>=0)Z=arguments[Y];else{if(C===void 0)C=process.cwd();Z=C}if(D(Z),Z.length===0)continue;$=Z+"/"+$,L=Z.charCodeAt(0)===47}if($=Z1($,!L),L)if($.length>0)return"/"+$;else return"/";else if($.length>0)return $;else return"."}function c($){if(D($),$.length===0)return".";var L=$.charCodeAt(0)===47,C=$.charCodeAt($.length-1)===47;if($=Z1($,!L),$.length===0&&!L)$=".";if($.length>0&&C)$+="/";if(L)return"/"+$;return $}function V1($){return D($),$.length>0&&$.charCodeAt(0)===47}function z1(){if(arguments.length===0)return".";var $;for(var L=0;L<arguments.length;++L){var C=arguments[L];if(D(C),C.length>0)if($===void 0)$=C;else $+="/"+C}if($===void 0)return".";return c($)}function G1($,L){if(D($),D(L),$===L)return"";if($=R($),L=R(L),$===L)return"";var C=1;for(;C<$.length;++C)if($.charCodeAt(C)!==47)break;var Y=$.length,Z=Y-C,V=1;for(;V<L.length;++V)if(L.charCodeAt(V)!==47)break;var z=L.length,G=z-V,J=Z<G?Z:G,Q=-1,X=0;for(;X<=J;++X){if(X===J){if(G>J){if(L.charCodeAt(V+X)===47)return L.slice(V+X+1);else if(X===0)return L.slice(V+X)}else if(Z>J){if($.charCodeAt(C+X)===47)Q=X;else if(X===0)Q=0}break}var A=$.charCodeAt(C+X),W=L.charCodeAt(V+X);if(A!==W)break;else if(A===47)Q=X}var K="";for(X=C+Q+1;X<=Y;++X)if(X===Y||$.charCodeAt(X)===47)if(K.length===0)K+="..";else K+="/..";if(K.length>0)return K+L.slice(V+Q);else{if(V+=Q,L.charCodeAt(V)===47)++V;return L.slice(V)}}function X1($){return $}function J1($){if(D($),$.length===0)return".";var L=$.charCodeAt(0),C=L===47,Y=-1,Z=!0;for(var V=$.length-1;V>=1;--V)if(L=$.charCodeAt(V),L===47){if(!Z){Y=V;break}}else Z=!1;if(Y===-1)return C?"/":".";if(C&&Y===1)return"//";return $.slice(0,Y)}function Q1($,L){if(L!==void 0&&typeof L!=="string")throw new TypeError('"ext" argument must be a string');D($);var C=0,Y=-1,Z=!0,V;if(L!==void 0&&L.length>0&&L.length<=$.length){if(L.length===$.length&&L===$)return"";var z=L.length-1,G=-1;for(V=$.length-1;V>=0;--V){var J=$.charCodeAt(V);if(J===47){if(!Z){C=V+1;break}}else{if(G===-1)Z=!1,G=V+1;if(z>=0)if(J===L.charCodeAt(z)){if(--z===-1)Y=V}else z=-1,Y=G}}if(C===Y)Y=G;else if(Y===-1)Y=$.length;return $.slice(C,Y)}else{for(V=$.length-1;V>=0;--V)if($.charCodeAt(V)===47){if(!Z){C=V+1;break}}else if(Y===-1)Z=!1,Y=V+1;if(Y===-1)return"";return $.slice(C,Y)}}function A1($){D($);var L=-1,C=0,Y=-1,Z=!0,V=0;for(var z=$.length-1;z>=0;--z){var G=$.charCodeAt(z);if(G===47){if(!Z){C=z+1;break}continue}if(Y===-1)Z=!1,Y=z+1;if(G===46){if(L===-1)L=z;else if(V!==1)V=1}else if(L!==-1)V=-1}if(L===-1||Y===-1||V===0||V===1&&L===Y-1&&L===C+1)return"";return $.slice(L,Y)}function W1($){if($===null||typeof $!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof $);return a1("/",$)}function K1($){D($);var L={root:"",dir:"",base:"",ext:"",name:""};if($.length===0)return L;var C=$.charCodeAt(0),Y=C===47,Z;if(Y)L.root="/",Z=1;else Z=0;var V=-1,z=0,G=-1,J=!0,Q=$.length-1,X=0;for(;Q>=Z;--Q){if(C=$.charCodeAt(Q),C===47){if(!J){z=Q+1;break}continue}if(G===-1)J=!1,G=Q+1;if(C===46){if(V===-1)V=Q;else if(X!==1)X=1}else if(V!==-1)X=-1}if(V===-1||G===-1||X===0||X===1&&V===G-1&&V===z+1){if(G!==-1)if(z===0&&Y)L.base=L.name=$.slice(1,G);else L.base=L.name=$.slice(z,G)}else{if(z===0&&Y)L.name=$.slice(1,V),L.base=$.slice(1,G);else L.name=$.slice(z,V),L.base=$.slice(z,G);L.ext=$.slice(V,G)}if(z>0)L.dir=$.slice(0,z-1);else if(Y)L.dir="/";return L}var B1="/",U1=":",v1,F;var u=p1(()=>{v1=(($)=>($.posix=$,$))({resolve:R,normalize:c,isAbsolute:V1,join:z1,relative:G1,_makeLong:X1,dirname:J1,basename:Q1,extname:A1,format:W1,parse:K1,sep:B1,delimiter:U1,win32:null,posix:null}),F=v1});var g1=m((Z0)=>{var t1=/[|\\{}()[\]^$+*?.]/g,e1=Object.prototype.hasOwnProperty,i=function($,L){return e1.apply($,[L])};Z0.escapeRegExpChars=function($){if(!$)return"";return String($).replace(t1,"\\$&")};var $0={"&":"&","<":"<",">":">",'"':""","'":"'"},C0=/[&<>'"]/g;function L0($){return $0[$]||$}var Y0=`var _ENCODE_HTML_RULES = {
|
|
2
|
+
"&": "&"
|
|
3
|
+
, "<": "<"
|
|
4
|
+
, ">": ">"
|
|
5
|
+
, '"': """
|
|
6
|
+
, "'": "'"
|
|
7
|
+
}
|
|
8
|
+
, _MATCH_HTML = /[&<>'"]/g;
|
|
9
|
+
function encode_char(c) {
|
|
10
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
11
|
+
};
|
|
12
|
+
`;Z0.escapeXML=function($){return $==null?"":String($).replace(C0,L0)};function N1(){return Function.prototype.toString.call(this)+`;
|
|
13
|
+
`+Y0}try{if(typeof Object.defineProperty==="function")Object.defineProperty(Z0.escapeXML,"toString",{value:N1});else Z0.escapeXML.toString=N1}catch($){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}Z0.shallowCopy=function($,L){if(L=L||{},$!==null&&$!==void 0)for(var C in L){if(!i(L,C))continue;if(C==="__proto__"||C==="constructor")continue;$[C]=L[C]}return $};Z0.shallowCopyFromList=function($,L,C){if(C=C||[],L=L||{},$!==null&&$!==void 0)for(var Y=0;Y<C.length;Y++){var Z=C[Y];if(typeof L[Z]!="undefined"){if(!i(L,Z))continue;if(Z==="__proto__"||Z==="constructor")continue;$[Z]=L[Z]}}return $};Z0.cache={_data:{},set:function($,L){this._data[$]=L},get:function($){return this._data[$]},remove:function($){delete this._data[$]},reset:function(){this._data={}}};Z0.hyphenToCamel=function($){return $.replace(/-[a-z]/g,function(L){return L[1].toUpperCase()})};Z0.createNullProtoObjWherePossible=function(){if(typeof Object.create=="function")return function(){return Object.create(null)};if(!({__proto__:null}instanceof Object))return function(){return{__proto__:null}};return function(){return{}}}();Z0.hasOwnOnlyObject=function($){var L=Z0.createNullProtoObjWherePossible();for(var C in $)if(i($,C))L[C]=$[C];return L}});var S1=m((r0,A0)=>{A0.exports={name:"ejs",description:"Embedded JavaScript templates",keywords:["template","engine","ejs"],version:"3.1.10",author:"Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"npx jake test"}}});var T1=m((_1)=>{var o=(()=>({})),M=(u(),r1(E1)),B=g1(),F1=!1,W0=S1().version,K0="<",B0=">",U0="%",q1="locals",v0="ejs",E0="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",w1=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],N0=w1.concat("cache"),j1=/^\uFEFF/,d=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;_1.cache=B.cache;_1.fileLoader=o.readFileSync;_1.localsName=q1;_1.promiseImpl=new Function("return this;")().Promise;_1.resolveInclude=function($,L,C){var{dirname:Y,extname:Z,resolve:V}=M,z=V(C?L:Y(L),$),G=Z($);if(!G)z+=".ejs";return z};function f1($,L){var C;if(L.some(function(Y){return C=_1.resolveInclude($,Y,!0),o.existsSync(C)}))return C}function D0($,L){var C,Y,Z=L.views,V=/^[A-Za-z]+:\\|^\//.exec($);if(V&&V.length)if($=$.replace(/^\/*/,""),Array.isArray(L.root))C=f1($,L.root);else C=_1.resolveInclude($,L.root||"/",!0);else{if(L.filename){if(Y=_1.resolveInclude($,L.filename),o.existsSync(Y))C=Y}if(!C&&Array.isArray(Z))C=f1($,Z);if(!C&&typeof L.includer!=="function")throw new Error('Could not find the include file "'+L.escapeFunction($)+'"')}return C}function O($,L){var C,Y=$.filename,Z=arguments.length>1;if($.cache){if(!Y)throw new Error("cache option requires a filename");if(C=_1.cache.get(Y),C)return C;if(!Z)L=H1(Y).toString().replace(j1,"")}else if(!Z){if(!Y)throw new Error("Internal EJS error: no file name or template provided");L=H1(Y).toString().replace(j1,"")}if(C=_1.compile(L,$),$.cache)_1.cache.set(Y,C);return C}function g0($,L,C){var Y;if(!C)if(typeof _1.promiseImpl=="function")return new _1.promiseImpl(function(Z,V){try{Y=O($)(L),Z(Y)}catch(z){V(z)}});else throw new Error("Please provide a callback function");else{try{Y=O($)(L)}catch(Z){return C(Z)}C(null,Y)}}function H1($){return _1.fileLoader($)}function S0($,L){var C=B.shallowCopy(B.createNullProtoObjWherePossible(),L);if(C.filename=D0($,C),typeof L.includer==="function"){var Y=L.includer($,C.filename);if(Y){if(Y.filename)C.filename=Y.filename;if(Y.template)return O(C,Y.template)}}return O(C)}function M1($,L,C,Y,Z){var V=L.split(`
|
|
14
|
+
`),z=Math.max(Y-3,0),G=Math.min(V.length,Y+3),J=Z(C),Q=V.slice(z,G).map(function(X,A){var W=A+z+1;return(W==Y?" >> ":" ")+W+"| "+X}).join(`
|
|
15
|
+
`);throw $.path=J,$.message=(J||"ejs")+":"+Y+`
|
|
16
|
+
`+Q+`
|
|
17
|
+
|
|
18
|
+
`+$.message,$}function O1($){return $.replace(/;(\s*$)/,"$1")}_1.compile=function $(L,C){var Y;if(C&&C.scope){if(!F1)console.warn("`scope` option is deprecated and will be removed in EJS 3"),F1=!0;if(!C.context)C.context=C.scope;delete C.scope}return Y=new E(L,C),Y.compile()};_1.render=function($,L,C){var Y=L||B.createNullProtoObjWherePossible(),Z=C||B.createNullProtoObjWherePossible();if(arguments.length==2)B.shallowCopyFromList(Z,Y,w1);return O(Z,$)(Y)};_1.renderFile=function(){var $=Array.prototype.slice.call(arguments),L=$.shift(),C,Y={filename:L},Z,V;if(typeof arguments[arguments.length-1]=="function")C=$.pop();if($.length){if(Z=$.shift(),$.length)B.shallowCopy(Y,$.pop());else{if(Z.settings){if(Z.settings.views)Y.views=Z.settings.views;if(Z.settings["view cache"])Y.cache=!0;if(V=Z.settings["view options"],V)B.shallowCopy(Y,V)}B.shallowCopyFromList(Y,Z,N0)}Y.filename=L}else Z=B.createNullProtoObjWherePossible();return g0(Y,Z,C)};_1.Template=E;_1.clearCache=function(){_1.cache.reset()};function E($,L){var C=B.hasOwnOnlyObject(L),Y=B.createNullProtoObjWherePossible();if(this.templateText=$,this.mode=null,this.truncate=!1,this.currentLine=1,this.source="",Y.client=C.client||!1,Y.escapeFunction=C.escape||C.escapeFunction||B.escapeXML,Y.compileDebug=C.compileDebug!==!1,Y.debug=!!C.debug,Y.filename=C.filename,Y.openDelimiter=C.openDelimiter||_1.openDelimiter||K0,Y.closeDelimiter=C.closeDelimiter||_1.closeDelimiter||B0,Y.delimiter=C.delimiter||_1.delimiter||U0,Y.strict=C.strict||!1,Y.context=C.context,Y.cache=C.cache||!1,Y.rmWhitespace=C.rmWhitespace,Y.root=C.root,Y.includer=C.includer,Y.outputFunctionName=C.outputFunctionName,Y.localsName=C.localsName||_1.localsName||q1,Y.views=C.views,Y.async=C.async,Y.destructuredLocals=C.destructuredLocals,Y.legacyInclude=typeof C.legacyInclude!="undefined"?!!C.legacyInclude:!0,Y.strict)Y._with=!1;else Y._with=typeof C._with!="undefined"?C._with:!0;this.opts=Y,this.regex=this.createRegex()}E.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};E.prototype={createRegex:function(){var $=E0,L=B.escapeRegExpChars(this.opts.delimiter),C=B.escapeRegExpChars(this.opts.openDelimiter),Y=B.escapeRegExpChars(this.opts.closeDelimiter);return $=$.replace(/%/g,L).replace(/</g,C).replace(/>/g,Y),new RegExp($)},compile:function(){var $,L,C=this.opts,Y="",Z="",V=C.escapeFunction,z,G=C.filename?JSON.stringify(C.filename):"undefined";if(!this.source){if(this.generateSource(),Y+=` var __output = "";
|
|
19
|
+
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
+
`,C.outputFunctionName){if(!d.test(C.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");Y+=" var "+C.outputFunctionName+` = __append;
|
|
21
|
+
`}if(C.localsName&&!d.test(C.localsName))throw new Error("localsName is not a valid JS identifier.");if(C.destructuredLocals&&C.destructuredLocals.length){var J=" var __locals = ("+C.localsName+` || {}),
|
|
22
|
+
`;for(var Q=0;Q<C.destructuredLocals.length;Q++){var X=C.destructuredLocals[Q];if(!d.test(X))throw new Error("destructuredLocals["+Q+"] is not a valid JS identifier.");if(Q>0)J+=`,
|
|
23
|
+
`;J+=X+" = __locals."+X}Y+=J+`;
|
|
24
|
+
`}if(C._with!==!1)Y+=" with ("+C.localsName+` || {}) {
|
|
25
|
+
`,Z+=` }
|
|
26
|
+
`;Z+=` return __output;
|
|
27
|
+
`,this.source=Y+this.source+Z}if(C.compileDebug)$=`var __line = 1
|
|
28
|
+
, __lines = `+JSON.stringify(this.templateText)+`
|
|
29
|
+
, __filename = `+G+`;
|
|
30
|
+
try {
|
|
31
|
+
`+this.source+`} catch (e) {
|
|
32
|
+
rethrow(e, __lines, __filename, __line, escapeFn);
|
|
33
|
+
}
|
|
34
|
+
`;else $=this.source;if(C.client){if($="escapeFn = escapeFn || "+V.toString()+`;
|
|
35
|
+
`+$,C.compileDebug)$="rethrow = rethrow || "+M1.toString()+`;
|
|
36
|
+
`+$}if(C.strict)$=`"use strict";
|
|
37
|
+
`+$;if(C.debug)console.log($);if(C.compileDebug&&C.filename)$=$+`
|
|
38
|
+
//# sourceURL=`+G+`
|
|
39
|
+
`;try{if(C.async)try{z=new Function("return (async function(){}).constructor;")()}catch(v){if(v instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw v}else z=Function;L=new z(C.localsName+", escapeFn, include, rethrow",$)}catch(v){if(v instanceof SyntaxError){if(C.filename)v.message+=" in "+C.filename;if(v.message+=` while compiling ejs
|
|
40
|
+
|
|
41
|
+
`,v.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
|
+
`,v.message+="https://github.com/RyanZim/EJS-Lint",!C.async)v.message+=`
|
|
43
|
+
`,v.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw v}var A=C.client?L:function v(f){var g=function(N,k){var x=B.shallowCopy(B.createNullProtoObjWherePossible(),f);if(k)x=B.shallowCopy(x,k);return S0(N,C)(x)};return L.apply(C.context,[f||B.createNullProtoObjWherePossible(),V,g,M1])};if(C.filename&&typeof Object.defineProperty==="function"){var W=C.filename,K=M.basename(W,M.extname(W));try{Object.defineProperty(A,"name",{value:K,writable:!1,enumerable:!1,configurable:!0})}catch(v){}}return A},generateSource:function(){var $=this.opts;if($.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
|
+
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var L=this,C=this.parseTemplateText(),Y=this.opts.delimiter,Z=this.opts.openDelimiter,V=this.opts.closeDelimiter;if(C&&C.length)C.forEach(function(z,G){var J;if(z.indexOf(Z+Y)===0&&z.indexOf(Z+Y+Y)!==0){if(J=C[G+2],!(J==Y+V||J=="-"+Y+V||J=="_"+Y+V))throw new Error('Could not find matching close tag for "'+z+'".')}L.scanLine(z)})},parseTemplateText:function(){var $=this.templateText,L=this.regex,C=L.exec($),Y=[],Z;while(C){if(Z=C.index,Z!==0)Y.push($.substring(0,Z)),$=$.slice(Z);Y.push(C[0]),$=$.slice(C[0].length),C=L.exec($)}if($)Y.push($);return Y},_addOutput:function($){if(this.truncate)$=$.replace(/^(?:\r\n|\r|\n)/,""),this.truncate=!1;if(!$)return $;$=$.replace(/\\/g,"\\\\"),$=$.replace(/\n/g,"\\n"),$=$.replace(/\r/g,"\\r"),$=$.replace(/"/g,"\\\""),this.source+=' ; __append("'+$+`")
|
|
45
|
+
`},scanLine:function($){var L=this,C=this.opts.delimiter,Y=this.opts.openDelimiter,Z=this.opts.closeDelimiter,V=0;switch(V=$.split(`
|
|
46
|
+
`).length-1,$){case Y+C:case Y+C+"_":this.mode=E.modes.EVAL;break;case Y+C+"=":this.mode=E.modes.ESCAPED;break;case Y+C+"-":this.mode=E.modes.RAW;break;case Y+C+"#":this.mode=E.modes.COMMENT;break;case Y+C+C:this.mode=E.modes.LITERAL,this.source+=' ; __append("'+$.replace(Y+C+C,Y+C)+`")
|
|
47
|
+
`;break;case C+C+Z:this.mode=E.modes.LITERAL,this.source+=' ; __append("'+$.replace(C+C+Z,C+Z)+`")
|
|
48
|
+
`;break;case C+Z:case"-"+C+Z:case"_"+C+Z:if(this.mode==E.modes.LITERAL)this._addOutput($);this.mode=null,this.truncate=$.indexOf("-")===0||$.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case E.modes.EVAL:case E.modes.ESCAPED:case E.modes.RAW:if($.lastIndexOf("//")>$.lastIndexOf(`
|
|
49
|
+
`))$+=`
|
|
50
|
+
`}switch(this.mode){case E.modes.EVAL:this.source+=" ; "+$+`
|
|
51
|
+
`;break;case E.modes.ESCAPED:this.source+=" ; __append(escapeFn("+O1($)+`))
|
|
52
|
+
`;break;case E.modes.RAW:this.source+=" ; __append("+O1($)+`)
|
|
53
|
+
`;break;case E.modes.COMMENT:break;case E.modes.LITERAL:this._addOutput($);break}}else this._addOutput($)}if(L.opts.compileDebug&&V)this.currentLine+=V,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
+
`}};_1.escapeXML=B.escapeXML;_1.__express=_1.renderFile;_1.VERSION=W0;_1.name=v0;if(typeof window!="undefined")window.ejs=_1});class _{children;isEndOfWord;handler;isDynamic;pattern;path;method;constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[]}}class I{root;constructor(){this.root=new _}pushMidl($,...L){let C=this.root,Y=$.split("/").filter(Boolean);if($==="/"){C.handler.push(...L);return}for(let Z of Y){let V=Z;if(Z.startsWith(":"))V=":";if(!C.children[V])C.children[V]=new _;C=C.children[V]}C.handler.push(...L)}insert($,L){let C=this.root,Y=$.split("/").filter(Boolean);if($==="/"){C.isEndOfWord=!0,C.handler.push(L.handler),C.path=$,C.method.push(L.method);return}for(let Z of Y){let V=!1,z=Z;if(Z.startsWith(":"))V=!0,z=":";if(!C.children[z])C.children[z]=new _;C=C.children[z],C.isDynamic=V,C.pattern=Z}C.isEndOfWord=!0,C.path=$,C.method.push(L.method),C.handler.push(L.handler)}search($,L){let C=this.root,Y=$.split("/").filter(Boolean),Z=Y.length;for(let G of Y){let J=G;if(!C.children[J])if(C.children[":"])C=C.children[":"];else return null;else C=C.children[J]}let V=C.path.split("/").filter(Boolean);if(Z!==V.length)return null;if(C.method.indexOf(L)!==-1)return{path:C.path,handler:C.handler[0],pattern:C.pattern};return null}}function b($){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 r=null;async function _0(){if(!r){let $=await Promise.resolve().then(() => o1(T1(),1));r=$.default||$}return r}var I0={string:"text/plain; charset=utf-8",object:"application/json; charset=utf-8",Uint8Array:"application/octet-stream",ArrayBuffer:"application/octet-stream"};function q($,L,C,Y){let Z=null,V=null,z=null,G=null,J={},Q=null;return{req:$,server:L,pathname:C,status:200,headers:new Headers,setHeader(X,A){return this.headers.set(X,A),this},removeHeader(X){return this.headers.delete(X),this},set(X,A){return J[X]=A,this},get(X){return J[X]},get ip(){return this.server.requestIP($)?.address??null},get url(){if(!Q)Q=new URL($.url);return Q},get query(){if(!Z){if(!this.url.search)return{};Z=Object.fromEntries(this.url.searchParams)}return Z},get params(){if(!V&&Y)try{V=R0(Y,C)}catch(X){let A=X instanceof Error?X.message:String(X);throw new Error(`Failed to extract route parameters: ${A}`)}return V??{}},get body(){if($.method==="GET")return Promise.resolve({});if(!G)G=(async()=>{try{let X=await T0($);if(X.error)throw new Error(X.error);return Object.keys(X).length===0?null:X}catch(X){throw new Error("Invalid request body format")}})();return G},text(X,A=200){if(this.status=A,!this.headers.has("Content-Type"))this.headers.set("Content-Type","text/plain; charset=utf-8");return new Response(X,{status:A,headers:this.headers})},send(X,A=200){this.status=A;let W;if(X instanceof Uint8Array)W="Uint8Array";else if(X instanceof ArrayBuffer)W="ArrayBuffer";else W=typeof X;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",I0[W]??"text/plain; charset=utf-8");let K=W==="object"&&X!==null?JSON.stringify(X):X;return new Response(K,{status:A,headers:this.headers})},json(X,A=200){if(this.status=A,!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return Response.json(X,{status:A,headers:this.headers})},file(X,A,W=200){this.status=W;let K=Bun.file(X);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",A??b(X));return new Response(K,{status:W,headers:this.headers})},async ejs(X,A={},W=200){this.status=W;let K=await _0();try{let v=await Bun.file(X).text(),f=K.render(v,A),g=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(f,{status:W,headers:g})}catch(v){return console.error("EJS Rendering Error:",v),new Response("Error rendering template",{status:500})}},redirect(X,A=302){return this.status=A,this.headers.set("Location",X),new Response(null,{status:A,headers:this.headers})},stream(X){let A=new Headers(this.headers),W=new ReadableStream({async start(K){await X(K),K.close()}});return new Response(W,{headers:A})},yieldStream(X){return new Response("not working stream yet.")},setCookie(X,A,W={}){let K=`${encodeURIComponent(X)}=${encodeURIComponent(A)}`;if(W.maxAge)K+=`; Max-Age=${W.maxAge}`;if(W.expires)K+=`; Expires=${W.expires.toUTCString()}`;if(W.path)K+=`; Path=${W.path}`;if(W.domain)K+=`; Domain=${W.domain}`;if(W.secure)K+="; Secure";if(W.httpOnly)K+="; HttpOnly";if(W.sameSite)K+=`; SameSite=${W.sameSite}`;return this.headers.append("Set-Cookie",K),this},get cookies(){if(!z){let X=this.req.headers.get("cookie");z=X?b0(X):{}}return z}}}function b0($){return Object.fromEntries($.split(";").map((L)=>{let[C,...Y]=L.trim().split("=");return[C,decodeURIComponent(Y.join("="))]}))}function R0($,L){let C={},Y=$.split("/"),[Z]=L.split("?"),V=Z.split("/");if(Y.length!==V.length)return null;for(let z=0;z<Y.length;z++){let G=Y[z];if(G.charCodeAt(0)===58)C[G.slice(1)]=V[z]}return C}async function T0($){let L=$.headers.get("Content-Type")||"";if(!L)return{};if($.headers.get("Content-Length")==="0"||!$.body)return{};if(L.startsWith("application/json"))return await $.json();if(L.startsWith("application/x-www-form-urlencoded")){let Y=await $.text();return Object.fromEntries(new URLSearchParams(Y))}if(L.startsWith("multipart/form-data")){let Y=await $.formData(),Z={};for(let[V,z]of Y.entries())Z[V]=z;return Z}return{error:"Unknown request body type"}}var P0=($,L)=>{try{return L($)}catch{return $.replace(/(?:%[0-9A-Fa-f]{2})+/g,(C)=>{try{return L(C)}catch{return C}})}},l=($)=>P0($,decodeURI),P1=($)=>{let L=$.indexOf("/",$.indexOf(":")+4),C=L;for(;C<$.length;C++){let Y=$.charCodeAt(C);if(Y===37){let Z=$.indexOf("?",C),V=$.slice(L,Z===-1?void 0:Z);return l(V.includes("%25")?V.replace(/%25/g,"%2525"):V)}else if(Y===63)break}return $.slice(L,C)};async function y0($,L,C){let Y,Z=$.url.indexOf("/",$.url.indexOf(":")+4),V=Z;for(;V<$.url.length;V++){let X=$.url.charCodeAt(V);if(X===37){let A=$.url.indexOf("?",V),W=$.url.slice(Z,A===-1?void 0:A);Y=l(W.includes("%25")?W.replace(/%25/g,"%2525"):W);break}else if(X===63)break}if(!Y)Y=$.url.slice(Z,V);let z=C.trie.search(Y,$.method),G=q($,L,Y,z?.path);if(C.hasOnReqHook)await S("onRequest",C.hooks.onRequest,[$,Y,L]);if(C.hasMiddleware){let X=await k0(C,Y,G);if(X)return X}if(C.hasFilterEnabled){let X=await p(C,Y,G);if(X)return X}if(!z)return await s(C,G,Y);if(C.hasPreHandlerHook){let X=await S("preHandler",C.hooks.preHandler,[G]);if(X)return X}let J=z.handler(G),Q=J instanceof Promise?await J:J;if(C.hasOnSendHook){let X=await S("onSend",C.hooks.onSend,[G,Q]);if(X)return X}if(Q instanceof Response)return Q;return j(500,"No response returned from handler.")}async function S($,L,C){if(!L?.length)return;for(let Y=0;Y<L.length;Y++){let Z=L[Y](...C),V=Z instanceof Promise?await Z:Z;if(V&&$!=="onRequest")return V}}async function k0($,L,C){let Y=$.globalMiddlewares;if(Y.length)for(let V of Y){let z=await V(C);if(z)return z}let Z=$.middlewares.get(L);if(Z&&Z.length)for(let V of Z){let z=await V(C);if(z)return z}return null}async function y1($,L,C){for(let Y of $){let Z=await Y(L,C);if(Z)return Z}}async function p($,L,C){let Y=await x0($,L,C),Z=Y instanceof Promise?await Y:Y;if(Z)return Z}async function x0($,L,C){if(L.endsWith("/"))L=L.slice(0,-1);if(!$.filters.has(L))if($.filterFunction.length)for(let Y of $.filterFunction){let Z=await Y(C);if(Z)return Z}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function V$($,L,C,Y){if(!$.filters.has(L))if($.filterFunction.length)for(let Z of $.filterFunction){let V=await Z(C,Y);if(V)return V}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function s($,L,C){if($.staticPath){let Z=await m0($,C,L);if(Z)return Z;let V=$.trie.search("*",L.req.method);if(V?.handler)return await V.handler(L)}return $.routeNotFoundFunc(L)||j(404,`Route not found for ${C}`)}function j($,L){return new Response(JSON.stringify({error:L}),{status:$,headers:{"Content-Type":"application/json"}})}async function m0($,L,C){if(!$.staticPath)return null;let Y=`${$.staticPath}${L}`;if(await Bun.file(Y).exists()){let V=b(Y);return C.file(Y,V,200)}return null}var y=($)=>$.constructor.name==="AsyncFunction",a=($,L,C,...Y)=>{if(L.length>5)$.push(`
|
|
55
|
+
for (let i = 0; i < diesel.hooks.${C}.length; i++) {
|
|
56
|
+
const result = diesel.hooks.${C}[i](${Y});
|
|
57
|
+
const finalResult = result instanceof Promise ? await result : result;
|
|
58
|
+
if (finalResult && '${C}' !== 'onRequest') return finalResult
|
|
59
|
+
}
|
|
60
|
+
`);else L?.forEach((Z,V)=>{if(y(Z))$.push(`
|
|
61
|
+
const ${C}${V}Result = await diesel.hooks.${C}[${V}](${Y})
|
|
62
|
+
if (${C}${V}Result && '${C}' !== 'onRequest') return ${C}${V}Result
|
|
63
|
+
`);else $.push(`
|
|
64
|
+
const ${C}${V}Result = diesel.hooks.${C}[${V}](${Y})
|
|
65
|
+
if (${C}${V}Result && '${C}' !== 'onRequest') return ${C}${V}Result
|
|
66
|
+
`)})},c0=($)=>{$.push(`
|
|
67
|
+
let pathname;
|
|
68
|
+
const start = req.url.indexOf('/', req.url.indexOf(':') + 4);
|
|
69
|
+
let i = start;
|
|
70
|
+
for (; i < req.url.length; i++) {
|
|
71
|
+
const charCode = req.url.charCodeAt(i);
|
|
72
|
+
if (charCode === 37) { // percent-encoded
|
|
73
|
+
const queryIndex = req.url.indexOf('?', i);
|
|
74
|
+
const path = req.url.slice(start, queryIndex === -1 ? undefined : queryIndex);
|
|
75
|
+
pathname = tryDecodeURI(path.includes('%25') ? path.replace(/%25/g, '%2525') : path);
|
|
76
|
+
break;
|
|
77
|
+
} else if (charCode === 63) { // ?
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!pathname) {
|
|
82
|
+
pathname = req.url.slice(start, i);
|
|
83
|
+
}
|
|
84
|
+
`)},u0=($,L)=>{if(L.length<=5)for(let C=0;C<L.length;C++)if(y(L[C]))$.push(`
|
|
85
|
+
const resultMiddleware${C} = await globalMiddlewares[${C}](ctx);
|
|
86
|
+
if (resultMiddleware${C}) return resultMiddleware${C};
|
|
87
|
+
`);else $.push(`
|
|
88
|
+
const resultMiddleware${C} = globalMiddlewares[${C}](ctx);
|
|
89
|
+
if (resultMiddleware${C}) return resultMiddleware${C};
|
|
90
|
+
`);else $.push(`
|
|
91
|
+
for (let i = 0; i < globalMiddlewares.length; i++) {
|
|
92
|
+
const result = await globalMiddlewares[i](ctx);
|
|
93
|
+
if (result) return result;
|
|
94
|
+
}
|
|
95
|
+
`)},k1=($,L)=>{let C=[],Y=L.globalMiddlewares||[],Z=$?.hasOnReqHook?L.hooks.onRequest:[],V=$?.hasPreHandlerHook?L.hooks.preHandler:[],z=$?.hasOnSendHook?L.hooks.onSend:[];if(c0(C),C.push(`
|
|
96
|
+
const routeHandler = diesel.trie.search(pathname, req.method);
|
|
97
|
+
`),Z&&Z.length>0)a(C,Z,"onRequest","req","pathname","server");if(C.push(`
|
|
98
|
+
const ctx = createCtx(req, server, pathname, routeHandler?.path);
|
|
99
|
+
`),$?.hasMiddleware){if(Y.length>0)u0(C,Y);if(L.middlewares.size>0)C.push(`
|
|
100
|
+
const local = diesel.middlewares.get(pathname)
|
|
101
|
+
if (local && local.length) {
|
|
102
|
+
for (const middleware of local) {
|
|
103
|
+
const result = await middleware(ctx);
|
|
104
|
+
if (result) return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`)}if($.hasFilterEnabled)C.push(`
|
|
108
|
+
const filterResponse = await runFilter(diesel, pathname, ctx);
|
|
109
|
+
if (filterResponse) return filterResponse;
|
|
110
|
+
`);if(C.push(`
|
|
111
|
+
if (!routeHandler) return await handleRouteNotFound(diesel, ctx, pathname);
|
|
112
|
+
`),$.hasPreHandlerHook)a(C,V,"preHandler","ctx");if(C.push(`
|
|
113
|
+
const result = routeHandler.handler(ctx);
|
|
114
|
+
const finalResult = result instanceof Promise ? await result : result;
|
|
115
|
+
`),$.hasOnSendHook)a(C,z,"onSend","ctx","finalResult");C.push(`
|
|
116
|
+
if (finalResult instanceof Response) return finalResult;
|
|
117
|
+
return generateErrorResponse(500, "No response returned from handler.");
|
|
118
|
+
`);let G=`
|
|
119
|
+
return async function pipeline(req, server, diesel) {
|
|
120
|
+
${C.join(`
|
|
121
|
+
`)}
|
|
122
|
+
}
|
|
123
|
+
`;return new Function("runFilter","handleRouteNotFound","generateErrorResponse","globalMiddlewares","createCtx",G)(p,s,j,Y,q)},x1=($,L,C,Y,...Z)=>{let V=[],z;if(typeof Z[0]==="string"||typeof Z[0]==="object")z=Z[0];let G=Z,J=$?.hasMiddleware?L.globalMiddlewares:[],Q=$?.hasMiddleware?L.middlewares.get(Y)||[]:[],X=[...J,...Q],A=$?.hasOnReqHook?L.hooks.onRequest:[],W=L.filters.has(Y),K=L.filterFunction;if(A&&A?.length>0)V.push(`
|
|
124
|
+
const onRequestResult = await runHooks(
|
|
125
|
+
"onRequest",
|
|
126
|
+
onRequestHooks,
|
|
127
|
+
[req, "${Y}", server]
|
|
128
|
+
);
|
|
129
|
+
if (onRequestResult) return onRequestResult;
|
|
130
|
+
`);if(X.length)V.push(`
|
|
131
|
+
const globalMiddlewareResponse = await executeBunMiddlewares(
|
|
132
|
+
allMiddlewares,
|
|
133
|
+
req,
|
|
134
|
+
server
|
|
135
|
+
);
|
|
136
|
+
if (globalMiddlewareResponse) return globalMiddlewareResponse;
|
|
137
|
+
`);if($.hasFilterEnabled){if(!W)V.push(`if (${K.length}) {
|
|
138
|
+
for (const filterFunction of filterFunctions) {
|
|
139
|
+
const filterResult = await filterFunction(req, server);
|
|
140
|
+
if (filterResult) return filterResult;
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
return Response.json({ error: "Protected route, authentication required" }, { status: 401 });
|
|
144
|
+
}`)}if(V.push(`
|
|
145
|
+
if ("${C}" !== req.method)
|
|
146
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
147
|
+
`),typeof z!=="undefined")if(typeof z==="string")V.push(`
|
|
148
|
+
return new Response(${JSON.stringify(z)});
|
|
149
|
+
`);else{let g=JSON.stringify(z);V.push(`
|
|
150
|
+
return new Response(${JSON.stringify(g)}, {
|
|
151
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
152
|
+
});
|
|
153
|
+
`)}else if(G.length===1){let g=G[0];if(y(g))V.push(`
|
|
154
|
+
const response = await handlers[0](req, server);
|
|
155
|
+
if (response instanceof Response) return response;
|
|
156
|
+
`);else V.push(`
|
|
157
|
+
const response = handlers[0](req, server);
|
|
158
|
+
if (response instanceof Response) return response;
|
|
159
|
+
`)}else G.forEach((g,N)=>{if(y(g))V.push(`
|
|
160
|
+
const response${N} = await handlers[${N}](req, server);
|
|
161
|
+
if (response${N} instanceof Response) return response${N};
|
|
162
|
+
`);else V.push(`
|
|
163
|
+
const response${N} = handlers[${N}](req, server);
|
|
164
|
+
if (response${N} instanceof Response) return response${N};
|
|
165
|
+
`)});let v=`
|
|
166
|
+
return async function(req, server) {
|
|
167
|
+
${V.join(`
|
|
168
|
+
`)}
|
|
169
|
+
}
|
|
170
|
+
`;return new Function("executeBunMiddlewares","handlers","runHooks","filterFunctions","onRequestHooks","allMiddlewares",v)(y1,G,S,K,A,X)};u();var{default:$1}=(()=>({}));var U={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"}},t=($,L,C)=>{let Y=U[$]||U.reset,Z=C?.method?U.method[C.method]||U.reset:U.reset,V=C?.status?C.status>=500?U.error:C.status>=400?U.warn:U.info:U.reset;console.log(`
|
|
171
|
+
${Y}[${$.toUpperCase()}]${U.reset} ${L} - ${Z}${C?.method||""}${U.reset}`);let z={timestamp:new Date().toISOString(),...C,status:C?.status?`${V}${C.status}${U.reset}`:void 0,method:C?.method?`${Z>Y}${C.method}${U.reset}`:void 0};console.log(JSON.stringify(z,null,2)+`
|
|
172
|
+
`)},m1=($)=>{let{app:L,logger:C,logLevel:Y="info",onRequest:Z,onSend:V,onError:z}=$||{};L?.addHooks("onRequest",(G,J)=>{G.startTime=Date.now(),C?.()??t(Y,"Incoming Request",{method:G.method,url:J,headers:{"user-agent":G.headers.get("user-agent"),"content-type":G.headers.get("content-type")}}),Z?.(G,J)}),L?.addHooks("onSend",async(G)=>{let J=`${Date.now()-G.req.startTime}ms`;C?.()??t(Y,"Response Sent",{method:G.req.method,url:G.url.toString(),status:G.status,duration:J,reqId:G.get?.("requestId"),headers:{"content-type":G.headers.get("content-type")}});let Q=await V?.(G);if(Q instanceof Response)return Q}),L?.addHooks("onError",async(G,J,Q)=>{C?.()??t("error","Unhandled Error",{method:J.method,url:Q,status:500,error:G.message});let X=await z?.(G,J,Q);if(X instanceof Response)return X})},e=($,L,C,Y=0,Z,V)=>{let z=U.method[L]||U.reset,G=Y>=500?U.error:Y>=400?U.warn:U.info,J=V?`[${V}] `:"",Q=$==="<--"?`${$} ${z}${L}${U.reset} ${C} ${J}`:`${$} ${z}${L}${U.reset} ${C} ${G}${Y}${U.reset} ${Z??""} ${J}`;console.log(Q)},h0=($)=>{let L=Date.now()-$;return L<1000?`${L}ms`:`${Math.round(L/1000)}s`},c1=($)=>{let{app:L,log:C,onRequest:Y,onSend:Z,onError:V}=$;L.addHooks("onRequest",(z,G)=>{z.startTime=Date.now(),C?.()??e("<--",z.method,G),Y?.(z,G)}),L.addHooks("onSend",async(z)=>{let{method:G,url:J}=z.req,Q=new URL(J).pathname,X=z.get?.("requestId");C?.()??e("-->",G,Q,z.status,h0(z.req.startTime),X);let A=await Z?.(z);if(A instanceof Response)return A}),L.addHooks("onError",async(z,G,J)=>{C?.()??e(z.message,G.method,J,500);let Q=await V?.(z,G,J);if(Q instanceof Response)return Q})};function u1($,L){if(!$)throw new Error("JWT library is not defined, please provide jwt to authenticateJwt Function");return(C)=>{try{let Y=C.cookies?.accessToken??C.req?.headers?.get("Authorization");if(!Y)return C.json({message:"Unauthorized",error:"No token provided"},401);if(Y.startsWith("Bearer "))Y=Y.slice(7);let Z=$?.verify(Y,L);if(!Z)return C.json({message:"Unauthorized",error:"Token could not be decoded"},401);C.set("user",Z)}catch(Y){let Z="Invalid token";if(Y.name==="TokenExpiredError")Z="Token expired";else if(Y.name==="JsonWebTokenError")Z="Malformed or tampered token";return C.json({message:"Unauthorized",error:Z},401)}}}function h1($,L,C){if(!$)throw new Error("JWT library is not defined, please provide jwt to authenticateJwtDB Function");if(!L)throw new Error("User model is not defined, please provide UserModel to authenticateJwtDB Function");return async(Y)=>{try{let Z=Y.cookies?.accessToken??Y.req?.headers?.get("Authorization");if(!Z)return Y.json({message:"Unauthorized",error:"No token provided"},401);if(Z.startsWith("Bearer "))Z=Z.slice(7);let V=$?.verify(Z,C);if(!V)return Y.json({message:"Unauthorized",error:"Token could not be decoded"},401);let z=await L.findById(V._id).select("-password -refreshToken");if(!z)return Y.json({message:"Unauthorized: User not found"},404);Y.set("user",z);return}catch(Z){let V="Invalid token";if(Z.name==="TokenExpiredError")V="Token expired";else if(Z.name==="JsonWebTokenError")V="Malformed or tampered token";return Y.json({message:"Unauthorized",error:V},401)}}}class w{static instance;fecth;routes;tempRoutes;globalMiddlewares;middlewares;trie;hasOnReqHook;hasMiddleware;hasPreHandlerHook;hasPostHandlerHook;hasOnSendHook;hasOnError;hooks;corsConfig;FilterRoutes;filters;filterFunction;hasFilterEnabled;serverInstance;staticPath;staticFiles;user_jwt_secret;baseApiUrl;enableFileRouter;idleTimeOut;routeNotFoundFunc;prefixApiUrl;compileConfig;constructor({jwtSecret:$,baseApiUrl:L,enableFileRouting:C,idleTimeOut:Y,prefixApiUrl:Z,onError:V,logger:z}={}){if(!w.instance)w.instance=this;if(this.prefixApiUrl=Z??"",this.fetch=this.fetch.bind(this),this.routes={},this.idleTimeOut=Y??10,this.enableFileRouter=C??!1,this.baseApiUrl=L||"",this.user_jwt_secret=$||process.env.DIESEL_JWT_SECRET||"feault_diesel_secret_for_jwt",this.tempRoutes=new Map,this.globalMiddlewares=[],this.middlewares=new Map,this.trie=new I,this.corsConfig=null,this.hasMiddleware=!1,this.hasOnReqHook=!1,this.hasPreHandlerHook=!1,this.hasPostHandlerHook=!1,this.hasOnSendHook=!1,this.hasOnError=!1,this.hooks={onRequest:[],preHandler:[],postHandler:[],onSend:[],onError:[],onClose:[]},V)this.addHooks("onError",(G)=>{return console.log("got an exception ",G),new Response(JSON.stringify({error:G?.message??G,stack:G.stack}),{headers:{"Content-Type":"application/json"},status:500})});if(z)this.useLogger({app:this,onError(G){return console.log("got an exception ",G),new Response(JSON.stringify({error:G?.message||G,stack:G.stack}),{headers:{"Content-Type":"application/json"},status:500})}});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 w;return new Proxy(this.instance,{get(L,C,Y){return(Z,V)=>{let z=$+Z;return L[C](z,V)}}})}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.FilterRoutes=null,this.setupFilter()},authenticate:($)=>{if($?.length)for(let L of $)this.filterFunction.push(L)},authenticateJwt:($)=>{this.filterFunction.push(u1($,this.user_jwt_secret))},authenticateJwtDB:($,L)=>{this.filterFunction.push(h1($,L,this.user_jwt_secret))}}}redirect($,L,C){return this.any($,(Y)=>{let Z=Y.params,V=L;if(Z)for(let G in Z)V=V.replace(`:${G}`,Z[G]);let z=Y.url.search;if(z)V+=z;return Y.redirect(V,C)}),this}serveStatic($){return this.staticPath=$,this}static($){return this.staticPath=$,this}staticHtml($){return this.staticFiles={...this.staticFiles,...$},this}addHooks($,L){if(typeof $!=="string")throw new Error("hookName must be a string");if(typeof L!=="function")throw new Error("callback must be a instance of function");switch($){case"onRequest":this.hooks.onRequest?.push(L);break;case"preHandler":this.hooks.preHandler?.push(L);break;case"postHandler":this.hooks.postHandler?.push(L);break;case"onSend":this.hooks.onSend?.push(L);break;case"onError":this.hooks.onError?.push(L);break;case"onClose":this.hooks.onClose?.push(L);break;default:throw new Error(`Unknown hook type: ${$}`)}return this}compile(){let $={hasMiddleware:!1,hasOnReqHook:!1,hasPreHandlerHook:!1,hasOnError:!1,hasPostHandlerHook:!1,hasOnSendHook:!1,hasFilterEnabled:!1};if(this.hasFilterEnabled)$.hasFilterEnabled=!0,this.hasFilterEnabled=!0;if(this?.globalMiddlewares?.length>0)$.hasMiddleware=!0,this.hasMiddleware=!0;for(let[L,C]of this?.middlewares?.entries())if(C.length>0){$.hasMiddleware=!0,this.hasMiddleware=!0;break}if(this?.enableFileRouter){let L=process.cwd(),C=F.join(L,"src","routes");if($1?.existsSync(C))this.loadRoutes(C,"")}if(this?.hooks?.onRequest&&this.hooks.onRequest.length>0)$.hasOnReqHook=!0,this.hasOnReqHook=!0;if(this?.hooks?.preHandler&&this.hooks.preHandler.length>0)$.hasPreHandlerHook=!0,this.hasPreHandlerHook=!0;if(this?.hooks?.postHandler&&this.hooks.postHandler?.length>0)$.hasPostHandlerHook=!0,this.hasPostHandlerHook=!0;if(this?.hooks?.onSend&&this.hooks.onSend?.length>0)$.hasOnSendHook=!0,this.hasOnSendHook=!0;if(this?.hooks?.onError&&this.hooks.onError?.length>0)$.hasOnError=!0,this.hasOnError=!0;return setTimeout(()=>{this.tempRoutes=null},2000),this.compileConfig=$,$}async registerFileRoutes($,L,C){let Y=await import($),Z;if(C===".ts")Z=F.basename($,".ts");else if(C===".js")Z=F.basename($,".js");let V=L+"/"+Z;if(V.endsWith("/index"))V=L;else if(V.endsWith("/api"))V=L;V=V.replace(/\[(.*?)\]/g,":$1");let z=["GET","POST","PUT","PATCH","DELETE","ANY","HEAD","OPTIONS","PROPFIND"];for(let G of z)if(Y[G]){let J=G.toLowerCase(),Q=Y[G];this[J](`${this.baseApiUrl}${V}`,Q)}}async loadRoutes($,L){let C=await $1.promises.readdir($);for(let Y of C){let Z=F.join($,Y);if((await $1.promises.stat(Z)).isDirectory())await this.loadRoutes(Z,L+"/"+Y);else if(Y.endsWith(".ts"))await this.registerFileRoutes(Z,L,".ts");else if(Y.endsWith(".js"))await this.registerFileRoutes(Z,L,".js")}}useLogger($){return c1($),this}useAdvancedLogger($){return m1($),this}BunRoute($,L,...C){if(!L||typeof L!=="string")throw new Error("give a path in string format");if(!this.compileConfig)this.compile();let Y;if(typeof C[0]==="string"||typeof C[0]==="object")Y=C[0];if(typeof Y!=="undefined"){let V=typeof Y==="string"?Y:JSON.stringify(Y)}let Z=x1(this.compileConfig,this,$.toUpperCase(),L,...C);return this.routes[L]=Z,this}listen($,...L){if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only...");let C="0.0.0.0",Y=void 0,Z={};for(let z of L)if(typeof z==="string")C=z;else if(typeof z==="function")Y=z;else if(typeof z==="object"&&z!==null)Z=z;let V={port:$,hostname:C,idleTimeOut:this.idleTimeOut,fetch:this.fetch(),static:this.staticFiles};if(this.routes&&Object.keys(this.routes).length>0)V.routes=this.routes;if(Z.cert&&Z.key)V.certFile=Z.cert,V.keyFile=Z.key;if(this.serverInstance=Bun?.serve(V),Y)Y();return this.serverInstance}fetch(){let $=this.compile(),L=k1($,this);return async(C,Y)=>{return L(C,Y,this).catch(async(Z)=>{return console.error("Unhandled handler error:",Z),await S("onError",this.hooks.onError,[Z,C,P1(C.url),Y])||j(500,"Internal Server Error")})}}close($){if(this.serverInstance)this.serverInstance.stop(!0),this.serverInstance=null,$?$():console.log("Server has been stopped");else console.warn("Server is not running.")}route($,L){$=$&&$.length>0?$:L?.prefixApiUrl;let C=L?.tempRoutes??new Map;for(let[Y,Z]of C.entries()){let V=Y.replace(/::\w+$/,""),z=`${$}${V}`;if(!this.middlewares.has(z))this.middlewares.set(z,[]);Z.handlers.slice(0,-1).forEach((X)=>{let A=this.middlewares.get(z);if(!A.includes(X))A.push(X)});let J=Z.handlers[Z.handlers.length-1],Q=Z.method;try{this.trie.insert(z,{handler:J,method:Q})}catch(X){console.error(`Error inserting ${z}:`,X)}}return L=null,this}register($,L){return this.route($,L)}addRoute($,L,C){if(typeof L!=="string")throw new Error(`Error in ${C[C.length-1]}: Path must be a string. Received: ${typeof L}`);if(typeof $!=="string")throw new Error(`Error in addRoute: Method must be a string. Received: ${typeof $}`);this.tempRoutes?.set(L+"::"+$,{method:$,handlers:C});let Y=C.slice(0,-1),Z=C[C.length-1];if(Y.length>0){if(!this.middlewares.has(L))this.middlewares.set(L,[]);Y.forEach((V)=>{if(L==="/")this.globalMiddlewares=[...new Set([...this.globalMiddlewares,...Y])];else if(!this.middlewares.get(L)?.includes(V))this.middlewares.get(L)?.push(V)})}try{if($==="ANY"){let V=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD","PROPFIND"];for(let z of V)this.trie.insert(L,{handler:Z,method:z})}this.trie.insert(L,{handler:Z,method:$})}catch(V){console.error(`Error inserting ${L}:`,V)}}use($,L){if(Array.isArray($))$.forEach((Y)=>{if(typeof Y==="function")this.globalMiddlewares.push(Y)});if(typeof $==="function"){if(this.globalMiddlewares.push($),Array.isArray(L))L.forEach((Y)=>{this.globalMiddlewares.push(Y)});return this}return(Array.isArray($)?$.filter((Y)=>typeof Y==="string"):[$].filter((Y)=>typeof Y==="string")).forEach((Y)=>{if(!this.middlewares.has(Y))this.middlewares.set(Y,[]);if(L)(Array.isArray(L)?L:[L]).forEach((V)=>{this.middlewares.get(Y)?.push(V)})}),this}get($,...L){return this.addRoute("GET",$,L),this}post($,...L){return this.addRoute("POST",$,L),this}put($,...L){return this.addRoute("PUT",$,L),this}patch($,...L){return this.addRoute("PATCH",$,L),this}delete($,...L){return this.addRoute("DELETE",$,L),this}any($,...L){return this.addRoute("ANY",$,L),this}head($,...L){return this.addRoute("HEAD",$,L),this}options($,...L){return this.addRoute("OPTIONS",$,L),this}propfind($,...L){return this.addRoute("PROPFIND",$,L),this}routeNotFound($){return this.routeNotFoundFunc=$,this}on($,L,...C){let Y=Array.isArray($)?$:[$];for(let Z of Y){let V=Z.toUpperCase();if(V.toLocaleLowerCase()in this)this[V.toLocaleLowerCase()](L,...C);else this.addRoute(V,L,C)}}}export{w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i=["GET","POST","PUT","DELETE","OPTIONS"],A=["Content-Type","Authorization"],g=(s)=>{return async function(e){let o=e.req.headers.get("origin")??"*",r=s.origin,t=s.allowedHeaders??A,a=s.methods??i,d=s.credentials??!1,n=s.exposedHeaders??[],l=s.maxAge;if(e.setHeader("Access-Control-Allow-Methods",a.join(",")),e.setHeader("Access-Control-Allow-Headers",t.join(",")),e.setHeader("Access-Control-Allow-Credentials",d.toString()),n.length>0)e.setHeader("Access-Control-Expose-Headers",n.join(","));if(r==="*"||o==="*")e.setHeader("Access-Control-Allow-Origin","*");else if(Array.isArray(r))if(o&&r.includes(o))e.setHeader("Access-Control-Allow-Origin",o);else if(r.includes("*"))e.setHeader("Access-Control-Allow-Origin","*");else return e.json({message:"CORS not allowed"},403);else if(typeof r==="string")if(o===r)e.setHeader("Access-Control-Allow-Origin",o);else return e.json({message:"CORS not allowed"},403);else return e.json({message:"CORS not allowed"},403);if(e.req.method==="OPTIONS"){if(l)e.setHeader("Access-Control-Max-Age",l.toString());return e.text("",204)}return null}};export{g as cors};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var g1=Object.create;var{getPrototypeOf:b1,defineProperty:F,getOwnPropertyNames:l,getOwnPropertyDescriptor:_1}=Object,o=Object.prototype.hasOwnProperty;var P1=(f,Y,z)=>{z=f!=null?g1(b1(f)):{};let Z=Y||!f||!f.__esModule?F(z,"default",{value:f,enumerable:!0}):z;for(let J of l(f))if(!o.call(Z,J))F(Z,J,{get:()=>f[J],enumerable:!0});return Z},i=new WeakMap,I1=(f)=>{var Y=i.get(f),z;if(Y)return Y;if(Y=F({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")l(f).map((Z)=>!o.call(Y,Z)&&F(Y,Z,{get:()=>f[Z],enumerable:!(z=_1(f,Z))||z.enumerable}));return i.set(f,Y),Y},q=(f,Y)=>()=>(Y||f((Y={exports:{}}).exports,Y),Y.exports);var R1=(f,Y)=>{for(var z in Y)F(f,z,{get:Y[z],enumerable:!0,configurable:!0,set:(Z)=>Y[z]=()=>Z})};var q1=(f,Y)=>()=>(f&&(Y=f(f=0)),Y);var T1=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(Y,z)=>(typeof require!=="undefined"?require:Y)[z]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var A1={};R1(A1,{sep:()=>$1,resolve:()=>M,relative:()=>t,posix:()=>X1,parse:()=>J1,normalize:()=>T,join:()=>s,isAbsolute:()=>a,format:()=>Z1,extname:()=>Y1,dirname:()=>f1,delimiter:()=>V1,default:()=>y1,basename:()=>z1,_makeLong:()=>e});function L(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function p(f,Y){var z="",Z=0,J=-1,$=0,X;for(var A=0;A<=f.length;++A){if(A<f.length)X=f.charCodeAt(A);else if(X===47)break;else X=47;if(X===47){if(J===A-1||$===1);else if(J!==A-1&&$===2){if(z.length<2||Z!==2||z.charCodeAt(z.length-1)!==46||z.charCodeAt(z.length-2)!==46){if(z.length>2){var Q=z.lastIndexOf("/");if(Q!==z.length-1){if(Q===-1)z="",Z=0;else z=z.slice(0,Q),Z=z.length-1-z.lastIndexOf("/");J=A,$=0;continue}}else if(z.length===2||z.length===1){z="",Z=0,J=A,$=0;continue}}if(Y){if(z.length>0)z+="/..";else z="..";Z=2}}else{if(z.length>0)z+="/"+f.slice(J+1,A);else z=f.slice(J+1,A);Z=A-J-1}J=A,$=0}else if(X===46&&$!==-1)++$;else $=-1}return z}function k1(f,Y){var z=Y.dir||Y.root,Z=Y.base||(Y.name||"")+(Y.ext||"");if(!z)return Z;if(z===Y.root)return z+Z;return z+f+Z}function M(){var f="",Y=!1,z;for(var Z=arguments.length-1;Z>=-1&&!Y;Z--){var J;if(Z>=0)J=arguments[Z];else{if(z===void 0)z=process.cwd();J=z}if(L(J),J.length===0)continue;f=J+"/"+f,Y=J.charCodeAt(0)===47}if(f=p(f,!Y),Y)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function T(f){if(L(f),f.length===0)return".";var Y=f.charCodeAt(0)===47,z=f.charCodeAt(f.length-1)===47;if(f=p(f,!Y),f.length===0&&!Y)f=".";if(f.length>0&&z)f+="/";if(Y)return"/"+f;return f}function a(f){return L(f),f.length>0&&f.charCodeAt(0)===47}function s(){if(arguments.length===0)return".";var f;for(var Y=0;Y<arguments.length;++Y){var z=arguments[Y];if(L(z),z.length>0)if(f===void 0)f=z;else f+="/"+z}if(f===void 0)return".";return T(f)}function t(f,Y){if(L(f),L(Y),f===Y)return"";if(f=M(f),Y=M(Y),f===Y)return"";var z=1;for(;z<f.length;++z)if(f.charCodeAt(z)!==47)break;var Z=f.length,J=Z-z,$=1;for(;$<Y.length;++$)if(Y.charCodeAt($)!==47)break;var X=Y.length,A=X-$,Q=J<A?J:A,W=-1,V=0;for(;V<=Q;++V){if(V===Q){if(A>Q){if(Y.charCodeAt($+V)===47)return Y.slice($+V+1);else if(V===0)return Y.slice($+V)}else if(J>Q){if(f.charCodeAt(z+V)===47)W=V;else if(V===0)W=0}break}var G=f.charCodeAt(z+V),j=Y.charCodeAt($+V);if(G!==j)break;else if(G===47)W=V}var C="";for(V=z+W+1;V<=Z;++V)if(V===Z||f.charCodeAt(V)===47)if(C.length===0)C+="..";else C+="/..";if(C.length>0)return C+Y.slice($+W);else{if($+=W,Y.charCodeAt($)===47)++$;return Y.slice($)}}function e(f){return f}function f1(f){if(L(f),f.length===0)return".";var Y=f.charCodeAt(0),z=Y===47,Z=-1,J=!0;for(var $=f.length-1;$>=1;--$)if(Y=f.charCodeAt($),Y===47){if(!J){Z=$;break}}else J=!1;if(Z===-1)return z?"/":".";if(z&&Z===1)return"//";return f.slice(0,Z)}function z1(f,Y){if(Y!==void 0&&typeof Y!=="string")throw new TypeError('"ext" argument must be a string');L(f);var z=0,Z=-1,J=!0,$;if(Y!==void 0&&Y.length>0&&Y.length<=f.length){if(Y.length===f.length&&Y===f)return"";var X=Y.length-1,A=-1;for($=f.length-1;$>=0;--$){var Q=f.charCodeAt($);if(Q===47){if(!J){z=$+1;break}}else{if(A===-1)J=!1,A=$+1;if(X>=0)if(Q===Y.charCodeAt(X)){if(--X===-1)Z=$}else X=-1,Z=A}}if(z===Z)Z=A;else if(Z===-1)Z=f.length;return f.slice(z,Z)}else{for($=f.length-1;$>=0;--$)if(f.charCodeAt($)===47){if(!J){z=$+1;break}}else if(Z===-1)J=!1,Z=$+1;if(Z===-1)return"";return f.slice(z,Z)}}function Y1(f){L(f);var Y=-1,z=0,Z=-1,J=!0,$=0;for(var X=f.length-1;X>=0;--X){var A=f.charCodeAt(X);if(A===47){if(!J){z=X+1;break}continue}if(Z===-1)J=!1,Z=X+1;if(A===46){if(Y===-1)Y=X;else if($!==1)$=1}else if(Y!==-1)$=-1}if(Y===-1||Z===-1||$===0||$===1&&Y===Z-1&&Y===z+1)return"";return f.slice(Y,Z)}function Z1(f){if(f===null||typeof f!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof f);return k1("/",f)}function J1(f){L(f);var Y={root:"",dir:"",base:"",ext:"",name:""};if(f.length===0)return Y;var z=f.charCodeAt(0),Z=z===47,J;if(Z)Y.root="/",J=1;else J=0;var $=-1,X=0,A=-1,Q=!0,W=f.length-1,V=0;for(;W>=J;--W){if(z=f.charCodeAt(W),z===47){if(!Q){X=W+1;break}continue}if(A===-1)Q=!1,A=W+1;if(z===46){if($===-1)$=W;else if(V!==1)V=1}else if($!==-1)V=-1}if($===-1||A===-1||V===0||V===1&&$===A-1&&$===X+1){if(A!==-1)if(X===0&&Z)Y.base=Y.name=f.slice(1,A);else Y.base=Y.name=f.slice(X,A)}else{if(X===0&&Z)Y.name=f.slice(1,$),Y.base=f.slice(1,A);else Y.name=f.slice(X,$),Y.base=f.slice(X,A);Y.ext=f.slice($,A)}if(X>0)Y.dir=f.slice(0,X-1);else if(Z)Y.dir="/";return Y}var $1="/",V1=":",X1,y1;var G1=q1(()=>{X1=((f)=>(f.posix=f,f))({resolve:M,normalize:T,isAbsolute:a,join:s,relative:t,_makeLong:e,dirname:f1,basename:z1,extname:Y1,format:Z1,parse:J1,sep:$1,delimiter:V1,win32:null,posix:null}),y1=X1});var W1=q((r1)=>{var x1=/[|\\{}()[\]^$+*?.]/g,c1=Object.prototype.hasOwnProperty,y=function(f,Y){return c1.apply(f,[Y])};r1.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(x1,"\\$&")};var m1={"&":"&","<":"<",">":">",'"':""","'":"'"},u1=/[&<>'"]/g;function h1(f){return m1[f]||f}var d1=`var _ENCODE_HTML_RULES = {
|
|
2
|
+
"&": "&"
|
|
3
|
+
, "<": "<"
|
|
4
|
+
, ">": ">"
|
|
5
|
+
, '"': """
|
|
6
|
+
, "'": "'"
|
|
7
|
+
}
|
|
8
|
+
, _MATCH_HTML = /[&<>'"]/g;
|
|
9
|
+
function encode_char(c) {
|
|
10
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
11
|
+
};
|
|
12
|
+
`;r1.escapeXML=function(f){return f==null?"":String(f).replace(u1,h1)};function j1(){return Function.prototype.toString.call(this)+`;
|
|
13
|
+
`+d1}try{if(typeof Object.defineProperty==="function")Object.defineProperty(r1.escapeXML,"toString",{value:j1});else r1.escapeXML.toString=j1}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}r1.shallowCopy=function(f,Y){if(Y=Y||{},f!==null&&f!==void 0)for(var z in Y){if(!y(Y,z))continue;if(z==="__proto__"||z==="constructor")continue;f[z]=Y[z]}return f};r1.shallowCopyFromList=function(f,Y,z){if(z=z||[],Y=Y||{},f!==null&&f!==void 0)for(var Z=0;Z<z.length;Z++){var J=z[Z];if(typeof Y[J]!="undefined"){if(!y(Y,J))continue;if(J==="__proto__"||J==="constructor")continue;f[J]=Y[J]}}return f};r1.cache={_data:{},set:function(f,Y){this._data[f]=Y},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};r1.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(Y){return Y[1].toUpperCase()})};r1.createNullProtoObjWherePossible=function(){if(typeof Object.create=="function")return function(){return Object.create(null)};if(!({__proto__:null}instanceof Object))return function(){return{__proto__:null}};return function(){return{}}}();r1.hasOwnOnlyObject=function(f){var Y=r1.createNullProtoObjWherePossible();for(var z in f)if(y(f,z))Y[z]=f[z];return Y}});var C1=q((P0,s1)=>{s1.exports={name:"ejs",description:"Embedded JavaScript templates",keywords:["template","engine","ejs"],version:"3.1.10",author:"Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"npx jake test"}}});var w1=q((H1)=>{var m=(()=>({})),H=(G1(),I1(A1)),U=W1(),U1=!1,t1=C1().version,e1="<",f0=">",z0="%",v1="locals",Y0="ejs",Z0="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",F1=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],J0=F1.concat("cache"),B1=/^\uFEFF/,x=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;H1.cache=U.cache;H1.fileLoader=m.readFileSync;H1.localsName=v1;H1.promiseImpl=new Function("return this;")().Promise;H1.resolveInclude=function(f,Y,z){var{dirname:Z,extname:J,resolve:$}=H,X=$(z?Y:Z(Y),f),A=J(f);if(!A)X+=".ejs";return X};function K1(f,Y){var z;if(Y.some(function(Z){return z=H1.resolveInclude(f,Z,!0),m.existsSync(z)}))return z}function $0(f,Y){var z,Z,J=Y.views,$=/^[A-Za-z]+:\\|^\//.exec(f);if($&&$.length)if(f=f.replace(/^\/*/,""),Array.isArray(Y.root))z=K1(f,Y.root);else z=H1.resolveInclude(f,Y.root||"/",!0);else{if(Y.filename){if(Z=H1.resolveInclude(f,Y.filename),m.existsSync(Z))z=Z}if(!z&&Array.isArray(J))z=K1(f,J);if(!z&&typeof Y.includer!=="function")throw new Error('Could not find the include file "'+Y.escapeFunction(f)+'"')}return z}function O(f,Y){var z,Z=f.filename,J=arguments.length>1;if(f.cache){if(!Z)throw new Error("cache option requires a filename");if(z=H1.cache.get(Z),z)return z;if(!J)Y=N1(Z).toString().replace(B1,"")}else if(!J){if(!Z)throw new Error("Internal EJS error: no file name or template provided");Y=N1(Z).toString().replace(B1,"")}if(z=H1.compile(Y,f),f.cache)H1.cache.set(Z,z);return z}function V0(f,Y,z){var Z;if(!z)if(typeof H1.promiseImpl=="function")return new H1.promiseImpl(function(J,$){try{Z=O(f)(Y),J(Z)}catch(X){$(X)}});else throw new Error("Please provide a callback function");else{try{Z=O(f)(Y)}catch(J){return z(J)}z(null,Z)}}function N1(f){return H1.fileLoader(f)}function X0(f,Y){var z=U.shallowCopy(U.createNullProtoObjWherePossible(),Y);if(z.filename=$0(f,z),typeof Y.includer==="function"){var Z=Y.includer(f,z.filename);if(Z){if(Z.filename)z.filename=Z.filename;if(Z.template)return O(z,Z.template)}}return O(z)}function L1(f,Y,z,Z,J){var $=Y.split(`
|
|
14
|
+
`),X=Math.max(Z-3,0),A=Math.min($.length,Z+3),Q=J(z),W=$.slice(X,A).map(function(V,G){var j=G+X+1;return(j==Z?" >> ":" ")+j+"| "+V}).join(`
|
|
15
|
+
`);throw f.path=Q,f.message=(Q||"ejs")+":"+Z+`
|
|
16
|
+
`+W+`
|
|
17
|
+
|
|
18
|
+
`+f.message,f}function D1(f){return f.replace(/;(\s*$)/,"$1")}H1.compile=function f(Y,z){var Z;if(z&&z.scope){if(!U1)console.warn("`scope` option is deprecated and will be removed in EJS 3"),U1=!0;if(!z.context)z.context=z.scope;delete z.scope}return Z=new K(Y,z),Z.compile()};H1.render=function(f,Y,z){var Z=Y||U.createNullProtoObjWherePossible(),J=z||U.createNullProtoObjWherePossible();if(arguments.length==2)U.shallowCopyFromList(J,Z,F1);return O(J,f)(Z)};H1.renderFile=function(){var f=Array.prototype.slice.call(arguments),Y=f.shift(),z,Z={filename:Y},J,$;if(typeof arguments[arguments.length-1]=="function")z=f.pop();if(f.length){if(J=f.shift(),f.length)U.shallowCopy(Z,f.pop());else{if(J.settings){if(J.settings.views)Z.views=J.settings.views;if(J.settings["view cache"])Z.cache=!0;if($=J.settings["view options"],$)U.shallowCopy(Z,$)}U.shallowCopyFromList(Z,J,J0)}Z.filename=Y}else J=U.createNullProtoObjWherePossible();return V0(Z,J,z)};H1.Template=K;H1.clearCache=function(){H1.cache.reset()};function K(f,Y){var z=U.hasOwnOnlyObject(Y),Z=U.createNullProtoObjWherePossible();if(this.templateText=f,this.mode=null,this.truncate=!1,this.currentLine=1,this.source="",Z.client=z.client||!1,Z.escapeFunction=z.escape||z.escapeFunction||U.escapeXML,Z.compileDebug=z.compileDebug!==!1,Z.debug=!!z.debug,Z.filename=z.filename,Z.openDelimiter=z.openDelimiter||H1.openDelimiter||e1,Z.closeDelimiter=z.closeDelimiter||H1.closeDelimiter||f0,Z.delimiter=z.delimiter||H1.delimiter||z0,Z.strict=z.strict||!1,Z.context=z.context,Z.cache=z.cache||!1,Z.rmWhitespace=z.rmWhitespace,Z.root=z.root,Z.includer=z.includer,Z.outputFunctionName=z.outputFunctionName,Z.localsName=z.localsName||H1.localsName||v1,Z.views=z.views,Z.async=z.async,Z.destructuredLocals=z.destructuredLocals,Z.legacyInclude=typeof z.legacyInclude!="undefined"?!!z.legacyInclude:!0,Z.strict)Z._with=!1;else Z._with=typeof z._with!="undefined"?z._with:!0;this.opts=Z,this.regex=this.createRegex()}K.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};K.prototype={createRegex:function(){var f=Z0,Y=U.escapeRegExpChars(this.opts.delimiter),z=U.escapeRegExpChars(this.opts.openDelimiter),Z=U.escapeRegExpChars(this.opts.closeDelimiter);return f=f.replace(/%/g,Y).replace(/</g,z).replace(/>/g,Z),new RegExp(f)},compile:function(){var f,Y,z=this.opts,Z="",J="",$=z.escapeFunction,X,A=z.filename?JSON.stringify(z.filename):"undefined";if(!this.source){if(this.generateSource(),Z+=` var __output = "";
|
|
19
|
+
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
+
`,z.outputFunctionName){if(!x.test(z.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");Z+=" var "+z.outputFunctionName+` = __append;
|
|
21
|
+
`}if(z.localsName&&!x.test(z.localsName))throw new Error("localsName is not a valid JS identifier.");if(z.destructuredLocals&&z.destructuredLocals.length){var Q=" var __locals = ("+z.localsName+` || {}),
|
|
22
|
+
`;for(var W=0;W<z.destructuredLocals.length;W++){var V=z.destructuredLocals[W];if(!x.test(V))throw new Error("destructuredLocals["+W+"] is not a valid JS identifier.");if(W>0)Q+=`,
|
|
23
|
+
`;Q+=V+" = __locals."+V}Z+=Q+`;
|
|
24
|
+
`}if(z._with!==!1)Z+=" with ("+z.localsName+` || {}) {
|
|
25
|
+
`,J+=` }
|
|
26
|
+
`;J+=` return __output;
|
|
27
|
+
`,this.source=Z+this.source+J}if(z.compileDebug)f=`var __line = 1
|
|
28
|
+
, __lines = `+JSON.stringify(this.templateText)+`
|
|
29
|
+
, __filename = `+A+`;
|
|
30
|
+
try {
|
|
31
|
+
`+this.source+`} catch (e) {
|
|
32
|
+
rethrow(e, __lines, __filename, __line, escapeFn);
|
|
33
|
+
}
|
|
34
|
+
`;else f=this.source;if(z.client){if(f="escapeFn = escapeFn || "+$.toString()+`;
|
|
35
|
+
`+f,z.compileDebug)f="rethrow = rethrow || "+L1.toString()+`;
|
|
36
|
+
`+f}if(z.strict)f=`"use strict";
|
|
37
|
+
`+f;if(z.debug)console.log(f);if(z.compileDebug&&z.filename)f=f+`
|
|
38
|
+
//# sourceURL=`+A+`
|
|
39
|
+
`;try{if(z.async)try{X=new Function("return (async function(){}).constructor;")()}catch(B){if(B instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw B}else X=Function;Y=new X(z.localsName+", escapeFn, include, rethrow",f)}catch(B){if(B instanceof SyntaxError){if(z.filename)B.message+=" in "+z.filename;if(B.message+=` while compiling ejs
|
|
40
|
+
|
|
41
|
+
`,B.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
|
+
`,B.message+="https://github.com/RyanZim/EJS-Lint",!z.async)B.message+=`
|
|
43
|
+
`,B.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw B}var G=z.client?Y:function B(v){var D=function(N,I){var R=U.shallowCopy(U.createNullProtoObjWherePossible(),v);if(I)R=U.shallowCopy(R,I);return X0(N,z)(R)};return Y.apply(z.context,[v||U.createNullProtoObjWherePossible(),$,D,L1])};if(z.filename&&typeof Object.defineProperty==="function"){var j=z.filename,C=H.basename(j,H.extname(j));try{Object.defineProperty(G,"name",{value:C,writable:!1,enumerable:!1,configurable:!0})}catch(B){}}return G},generateSource:function(){var f=this.opts;if(f.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
|
+
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var Y=this,z=this.parseTemplateText(),Z=this.opts.delimiter,J=this.opts.openDelimiter,$=this.opts.closeDelimiter;if(z&&z.length)z.forEach(function(X,A){var Q;if(X.indexOf(J+Z)===0&&X.indexOf(J+Z+Z)!==0){if(Q=z[A+2],!(Q==Z+$||Q=="-"+Z+$||Q=="_"+Z+$))throw new Error('Could not find matching close tag for "'+X+'".')}Y.scanLine(X)})},parseTemplateText:function(){var f=this.templateText,Y=this.regex,z=Y.exec(f),Z=[],J;while(z){if(J=z.index,J!==0)Z.push(f.substring(0,J)),f=f.slice(J);Z.push(z[0]),f=f.slice(z[0].length),z=Y.exec(f)}if(f)Z.push(f);return Z},_addOutput:function(f){if(this.truncate)f=f.replace(/^(?:\r\n|\r|\n)/,""),this.truncate=!1;if(!f)return f;f=f.replace(/\\/g,"\\\\"),f=f.replace(/\n/g,"\\n"),f=f.replace(/\r/g,"\\r"),f=f.replace(/"/g,"\\\""),this.source+=' ; __append("'+f+`")
|
|
45
|
+
`},scanLine:function(f){var Y=this,z=this.opts.delimiter,Z=this.opts.openDelimiter,J=this.opts.closeDelimiter,$=0;switch($=f.split(`
|
|
46
|
+
`).length-1,f){case Z+z:case Z+z+"_":this.mode=K.modes.EVAL;break;case Z+z+"=":this.mode=K.modes.ESCAPED;break;case Z+z+"-":this.mode=K.modes.RAW;break;case Z+z+"#":this.mode=K.modes.COMMENT;break;case Z+z+z:this.mode=K.modes.LITERAL,this.source+=' ; __append("'+f.replace(Z+z+z,Z+z)+`")
|
|
47
|
+
`;break;case z+z+J:this.mode=K.modes.LITERAL,this.source+=' ; __append("'+f.replace(z+z+J,z+J)+`")
|
|
48
|
+
`;break;case z+J:case"-"+z+J:case"_"+z+J:if(this.mode==K.modes.LITERAL)this._addOutput(f);this.mode=null,this.truncate=f.indexOf("-")===0||f.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case K.modes.EVAL:case K.modes.ESCAPED:case K.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
|
|
49
|
+
`))f+=`
|
|
50
|
+
`}switch(this.mode){case K.modes.EVAL:this.source+=" ; "+f+`
|
|
51
|
+
`;break;case K.modes.ESCAPED:this.source+=" ; __append(escapeFn("+D1(f)+`))
|
|
52
|
+
`;break;case K.modes.RAW:this.source+=" ; __append("+D1(f)+`)
|
|
53
|
+
`;break;case K.modes.COMMENT:break;case K.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(Y.opts.compileDebug&&$)this.currentLine+=$,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
+
`}};H1.escapeXML=U.escapeXML;H1.__express=H1.renderFile;H1.VERSION=t1;H1.name=Y0;if(typeof window!="undefined")window.ejs=H1});function w(f){switch(f.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 u=null;async function K0(){if(!u){let f=await Promise.resolve().then(() => P1(w1(),1));u=f.default||f}return u}var N0={string:"text/plain; charset=utf-8",object:"application/json; charset=utf-8",Uint8Array:"application/octet-stream",ArrayBuffer:"application/octet-stream"};function S(f,Y,z,Z){let J=null,$=null,X=null,A=null,Q={},W=null;return{req:f,server:Y,pathname:z,status:200,headers:new Headers,setHeader(V,G){return this.headers.set(V,G),this},removeHeader(V){return this.headers.delete(V),this},set(V,G){return Q[V]=G,this},get(V){return Q[V]},get ip(){return this.server.requestIP(f)?.address??null},get url(){if(!W)W=new URL(f.url);return W},get query(){if(!J){if(!this.url.search)return{};J=Object.fromEntries(this.url.searchParams)}return J},get params(){if(!$&&Z)try{$=D0(Z,z)}catch(V){let G=V instanceof Error?V.message:String(V);throw new Error(`Failed to extract route parameters: ${G}`)}return $??{}},get body(){if(f.method==="GET")return Promise.resolve({});if(!A)A=(async()=>{try{let V=await v0(f);if(V.error)throw new Error(V.error);return Object.keys(V).length===0?null:V}catch(V){throw new Error("Invalid request body format")}})();return A},text(V,G=200){if(this.status=G,!this.headers.has("Content-Type"))this.headers.set("Content-Type","text/plain; charset=utf-8");return new Response(V,{status:G,headers:this.headers})},send(V,G=200){this.status=G;let j;if(V instanceof Uint8Array)j="Uint8Array";else if(V instanceof ArrayBuffer)j="ArrayBuffer";else j=typeof V;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",N0[j]??"text/plain; charset=utf-8");let C=j==="object"&&V!==null?JSON.stringify(V):V;return new Response(C,{status:G,headers:this.headers})},json(V,G=200){if(this.status=G,!this.headers.has("Content-Type"))this.headers.set("Content-Type","application/json; charset=utf-8");return Response.json(V,{status:G,headers:this.headers})},file(V,G,j=200){this.status=j;let C=Bun.file(V);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",G??w(V));return new Response(C,{status:j,headers:this.headers})},async ejs(V,G={},j=200){this.status=j;let C=await K0();try{let B=await Bun.file(V).text(),v=C.render(B,G),D=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(v,{status:j,headers:D})}catch(B){return console.error("EJS Rendering Error:",B),new Response("Error rendering template",{status:500})}},redirect(V,G=302){return this.status=G,this.headers.set("Location",V),new Response(null,{status:G,headers:this.headers})},stream(V){let G=new Headers(this.headers),j=new ReadableStream({async start(C){await V(C),C.close()}});return new Response(j,{headers:G})},yieldStream(V){return new Response("not working stream yet.")},setCookie(V,G,j={}){let C=`${encodeURIComponent(V)}=${encodeURIComponent(G)}`;if(j.maxAge)C+=`; Max-Age=${j.maxAge}`;if(j.expires)C+=`; Expires=${j.expires.toUTCString()}`;if(j.path)C+=`; Path=${j.path}`;if(j.domain)C+=`; Domain=${j.domain}`;if(j.secure)C+="; Secure";if(j.httpOnly)C+="; HttpOnly";if(j.sameSite)C+=`; SameSite=${j.sameSite}`;return this.headers.append("Set-Cookie",C),this},get cookies(){if(!X){let V=this.req.headers.get("cookie");X=V?L0(V):{}}return X}}}function L0(f){return Object.fromEntries(f.split(";").map((Y)=>{let[z,...Z]=Y.trim().split("=");return[z,decodeURIComponent(Z.join("="))]}))}function D0(f,Y){let z={},Z=f.split("/"),[J]=Y.split("?"),$=J.split("/");if(Z.length!==$.length)return null;for(let X=0;X<Z.length;X++){let A=Z[X];if(A.charCodeAt(0)===58)z[A.slice(1)]=$[X]}return z}async function v0(f){let Y=f.headers.get("Content-Type")||"";if(!Y)return{};if(f.headers.get("Content-Length")==="0"||!f.body)return{};if(Y.startsWith("application/json"))return await f.json();if(Y.startsWith("application/x-www-form-urlencoded")){let Z=await f.text();return Object.fromEntries(new URLSearchParams(Z))}if(Y.startsWith("multipart/form-data")){let Z=await f.formData(),J={};for(let[$,X]of Z.entries())J[$]=X;return J}return{error:"Unknown request body type"}}var F0=(f,Y)=>{try{return Y(f)}catch{return f.replace(/(?:%[0-9A-Fa-f]{2})+/g,(z)=>{try{return Y(z)}catch{return z}})}},h=(f)=>F0(f,decodeURI),x0=(f)=>{let Y=f.indexOf("/",f.indexOf(":")+4),z=Y;for(;z<f.length;z++){let Z=f.charCodeAt(z);if(Z===37){let J=f.indexOf("?",z),$=f.slice(Y,J===-1?void 0:J);return h($.includes("%25")?$.replace(/%25/g,"%2525"):$)}else if(Z===63)break}return f.slice(Y,z)};async function H0(f,Y,z){let Z,J=f.url.indexOf("/",f.url.indexOf(":")+4),$=J;for(;$<f.url.length;$++){let V=f.url.charCodeAt($);if(V===37){let G=f.url.indexOf("?",$),j=f.url.slice(J,G===-1?void 0:G);Z=h(j.includes("%25")?j.replace(/%25/g,"%2525"):j);break}else if(V===63)break}if(!Z)Z=f.url.slice(J,$);let X=z.trie.search(Z,f.method),A=S(f,Y,Z,X?.path);if(z.hasOnReqHook)await E("onRequest",z.hooks.onRequest,[f,Z,Y]);if(z.hasMiddleware){let V=await O0(z,Z,A);if(V)return V}if(z.hasFilterEnabled){let V=await d(z,Z,A);if(V)return V}if(!X)return await r(z,A,Z);if(z.hasPreHandlerHook){let V=await E("preHandler",z.hooks.preHandler,[A]);if(V)return V}let Q=X.handler(A),W=Q instanceof Promise?await Q:Q;if(z.hasOnSendHook){let V=await E("onSend",z.hooks.onSend,[A,W]);if(V)return V}if(W instanceof Response)return W;return _(500,"No response returned from handler.")}async function E(f,Y,z){if(!Y?.length)return;for(let Z=0;Z<Y.length;Z++){let J=Y[Z](...z),$=J instanceof Promise?await J:J;if($&&f!=="onRequest")return $}}async function O0(f,Y,z){let Z=f.globalMiddlewares;if(Z.length)for(let $ of Z){let X=await $(z);if(X)return X}let J=f.middlewares.get(Y);if(J&&J.length)for(let $ of J){let X=await $(z);if(X)return X}return null}async function M1(f,Y,z){for(let Z of f){let J=await Z(Y,z);if(J)return J}}async function d(f,Y,z){let Z=await S0(f,Y,z),J=Z instanceof Promise?await Z:Z;if(J)return J}async function S0(f,Y,z){if(Y.endsWith("/"))Y=Y.slice(0,-1);if(!f.filters.has(Y))if(f.filterFunction.length)for(let Z of f.filterFunction){let J=await Z(z);if(J)return J}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function r0(f,Y,z,Z){if(!f.filters.has(Y))if(f.filterFunction.length)for(let J of f.filterFunction){let $=await J(z,Z);if($)return $}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function r(f,Y,z){if(f.staticPath){let J=await E0(f,z,Y);if(J)return J;let $=f.trie.search("*",Y.req.method);if($?.handler)return await $.handler(Y)}return f.routeNotFoundFunc(Y)||_(404,`Route not found for ${z}`)}function _(f,Y){return new Response(JSON.stringify({error:Y}),{status:f,headers:{"Content-Type":"application/json"}})}async function E0(f,Y,z){if(!f.staticPath)return null;let Z=`${f.staticPath}${Y}`;if(await Bun.file(Z).exists()){let $=w(Z);return z.file(Z,$,200)}return null}var P=(f)=>f.constructor.name==="AsyncFunction",n=(f,Y,z,...Z)=>{if(Y.length>5)f.push(`
|
|
55
|
+
for (let i = 0; i < diesel.hooks.${z}.length; i++) {
|
|
56
|
+
const result = diesel.hooks.${z}[i](${Z});
|
|
57
|
+
const finalResult = result instanceof Promise ? await result : result;
|
|
58
|
+
if (finalResult && '${z}' !== 'onRequest') return finalResult
|
|
59
|
+
}
|
|
60
|
+
`);else Y?.forEach((J,$)=>{if(P(J))f.push(`
|
|
61
|
+
const ${z}${$}Result = await diesel.hooks.${z}[${$}](${Z})
|
|
62
|
+
if (${z}${$}Result && '${z}' !== 'onRequest') return ${z}${$}Result
|
|
63
|
+
`);else f.push(`
|
|
64
|
+
const ${z}${$}Result = diesel.hooks.${z}[${$}](${Z})
|
|
65
|
+
if (${z}${$}Result && '${z}' !== 'onRequest') return ${z}${$}Result
|
|
66
|
+
`)})},w0=(f)=>{f.push(`
|
|
67
|
+
let pathname;
|
|
68
|
+
const start = req.url.indexOf('/', req.url.indexOf(':') + 4);
|
|
69
|
+
let i = start;
|
|
70
|
+
for (; i < req.url.length; i++) {
|
|
71
|
+
const charCode = req.url.charCodeAt(i);
|
|
72
|
+
if (charCode === 37) { // percent-encoded
|
|
73
|
+
const queryIndex = req.url.indexOf('?', i);
|
|
74
|
+
const path = req.url.slice(start, queryIndex === -1 ? undefined : queryIndex);
|
|
75
|
+
pathname = tryDecodeURI(path.includes('%25') ? path.replace(/%25/g, '%2525') : path);
|
|
76
|
+
break;
|
|
77
|
+
} else if (charCode === 63) { // ?
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!pathname) {
|
|
82
|
+
pathname = req.url.slice(start, i);
|
|
83
|
+
}
|
|
84
|
+
`)},M0=(f,Y)=>{if(Y.length<=5)for(let z=0;z<Y.length;z++)if(P(Y[z]))f.push(`
|
|
85
|
+
const resultMiddleware${z} = await globalMiddlewares[${z}](ctx);
|
|
86
|
+
if (resultMiddleware${z}) return resultMiddleware${z};
|
|
87
|
+
`);else f.push(`
|
|
88
|
+
const resultMiddleware${z} = globalMiddlewares[${z}](ctx);
|
|
89
|
+
if (resultMiddleware${z}) return resultMiddleware${z};
|
|
90
|
+
`);else f.push(`
|
|
91
|
+
for (let i = 0; i < globalMiddlewares.length; i++) {
|
|
92
|
+
const result = await globalMiddlewares[i](ctx);
|
|
93
|
+
if (result) return result;
|
|
94
|
+
}
|
|
95
|
+
`)},p0=(f,Y)=>{let z=[],Z=Y.globalMiddlewares||[],J=f?.hasOnReqHook?Y.hooks.onRequest:[],$=f?.hasPreHandlerHook?Y.hooks.preHandler:[],X=f?.hasOnSendHook?Y.hooks.onSend:[];if(w0(z),z.push(`
|
|
96
|
+
const routeHandler = diesel.trie.search(pathname, req.method);
|
|
97
|
+
`),J&&J.length>0)n(z,J,"onRequest","req","pathname","server");if(z.push(`
|
|
98
|
+
const ctx = createCtx(req, server, pathname, routeHandler?.path);
|
|
99
|
+
`),f?.hasMiddleware){if(Z.length>0)M0(z,Z);if(Y.middlewares.size>0)z.push(`
|
|
100
|
+
const local = diesel.middlewares.get(pathname)
|
|
101
|
+
if (local && local.length) {
|
|
102
|
+
for (const middleware of local) {
|
|
103
|
+
const result = await middleware(ctx);
|
|
104
|
+
if (result) return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`)}if(f.hasFilterEnabled)z.push(`
|
|
108
|
+
const filterResponse = await runFilter(diesel, pathname, ctx);
|
|
109
|
+
if (filterResponse) return filterResponse;
|
|
110
|
+
`);if(z.push(`
|
|
111
|
+
if (!routeHandler) return await handleRouteNotFound(diesel, ctx, pathname);
|
|
112
|
+
`),f.hasPreHandlerHook)n(z,$,"preHandler","ctx");if(z.push(`
|
|
113
|
+
const result = routeHandler.handler(ctx);
|
|
114
|
+
const finalResult = result instanceof Promise ? await result : result;
|
|
115
|
+
`),f.hasOnSendHook)n(z,X,"onSend","ctx","finalResult");z.push(`
|
|
116
|
+
if (finalResult instanceof Response) return finalResult;
|
|
117
|
+
return generateErrorResponse(500, "No response returned from handler.");
|
|
118
|
+
`);let A=`
|
|
119
|
+
return async function pipeline(req, server, diesel) {
|
|
120
|
+
${z.join(`
|
|
121
|
+
`)}
|
|
122
|
+
}
|
|
123
|
+
`;return new Function("runFilter","handleRouteNotFound","generateErrorResponse","globalMiddlewares","createCtx",A)(d,r,_,Z,S)},a0=(f,Y,z,Z,...J)=>{let $=[],X;if(typeof J[0]==="string"||typeof J[0]==="object")X=J[0];let A=J,Q=f?.hasMiddleware?Y.globalMiddlewares:[],W=f?.hasMiddleware?Y.middlewares.get(Z)||[]:[],V=[...Q,...W],G=f?.hasOnReqHook?Y.hooks.onRequest:[],j=Y.filters.has(Z),C=Y.filterFunction;if(G&&G?.length>0)$.push(`
|
|
124
|
+
const onRequestResult = await runHooks(
|
|
125
|
+
"onRequest",
|
|
126
|
+
onRequestHooks,
|
|
127
|
+
[req, "${Z}", server]
|
|
128
|
+
);
|
|
129
|
+
if (onRequestResult) return onRequestResult;
|
|
130
|
+
`);if(V.length)$.push(`
|
|
131
|
+
const globalMiddlewareResponse = await executeBunMiddlewares(
|
|
132
|
+
allMiddlewares,
|
|
133
|
+
req,
|
|
134
|
+
server
|
|
135
|
+
);
|
|
136
|
+
if (globalMiddlewareResponse) return globalMiddlewareResponse;
|
|
137
|
+
`);if(f.hasFilterEnabled){if(!j)$.push(`if (${C.length}) {
|
|
138
|
+
for (const filterFunction of filterFunctions) {
|
|
139
|
+
const filterResult = await filterFunction(req, server);
|
|
140
|
+
if (filterResult) return filterResult;
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
return Response.json({ error: "Protected route, authentication required" }, { status: 401 });
|
|
144
|
+
}`)}if($.push(`
|
|
145
|
+
if ("${z}" !== req.method)
|
|
146
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
147
|
+
`),typeof X!=="undefined")if(typeof X==="string")$.push(`
|
|
148
|
+
return new Response(${JSON.stringify(X)});
|
|
149
|
+
`);else{let D=JSON.stringify(X);$.push(`
|
|
150
|
+
return new Response(${JSON.stringify(D)}, {
|
|
151
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
152
|
+
});
|
|
153
|
+
`)}else if(A.length===1){let D=A[0];if(P(D))$.push(`
|
|
154
|
+
const response = await handlers[0](req, server);
|
|
155
|
+
if (response instanceof Response) return response;
|
|
156
|
+
`);else $.push(`
|
|
157
|
+
const response = handlers[0](req, server);
|
|
158
|
+
if (response instanceof Response) return response;
|
|
159
|
+
`)}else A.forEach((D,N)=>{if(P(D))$.push(`
|
|
160
|
+
const response${N} = await handlers[${N}](req, server);
|
|
161
|
+
if (response${N} instanceof Response) return response${N};
|
|
162
|
+
`);else $.push(`
|
|
163
|
+
const response${N} = handlers[${N}](req, server);
|
|
164
|
+
if (response${N} instanceof Response) return response${N};
|
|
165
|
+
`)});let B=`
|
|
166
|
+
return async function(req, server) {
|
|
167
|
+
${$.join(`
|
|
168
|
+
`)}
|
|
169
|
+
}
|
|
170
|
+
`;return new Function("executeBunMiddlewares","handlers","runHooks","filterFunctions","onRequestHooks","allMiddlewares",B)(M1,A,E,C,G,V)};export{p0 as buildRequestPipeline,a0 as BunRequestPipline};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Result, Router } from '../../router';
|
|
2
|
+
export declare class SmartRouter<T> implements Router<T> {
|
|
3
|
+
#private;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(init: {
|
|
6
|
+
routers: Router<T>[];
|
|
7
|
+
});
|
|
8
|
+
add(method: string, path: string, handler: T): void;
|
|
9
|
+
match(method: string, path: string): Result<T>;
|
|
10
|
+
get activeRouter(): Router<T>;
|
|
11
|
+
}
|
package/dist/trie.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { handlerFunction, HttpMethod, RouteHandlerT } from "./types";
|
|
1
|
+
import type { handlerFunction, HttpMethod, middlewareFunc, RouteHandlerT } from "./types";
|
|
2
2
|
declare class TrieNode {
|
|
3
3
|
children: Record<string, TrieNode>;
|
|
4
4
|
isEndOfWord: boolean;
|
|
5
|
-
handler: handlerFunction[];
|
|
5
|
+
handler: handlerFunction[] | middlewareFunc[] | any;
|
|
6
6
|
isDynamic: boolean;
|
|
7
7
|
pattern: string;
|
|
8
8
|
path: string;
|
|
@@ -12,10 +12,11 @@ declare class TrieNode {
|
|
|
12
12
|
export default class Trie {
|
|
13
13
|
root: TrieNode;
|
|
14
14
|
constructor();
|
|
15
|
+
pushMidl(path: string, ...middlewares: middlewareFunc[]): void;
|
|
15
16
|
insert(path: string, route: RouteHandlerT): void;
|
|
16
17
|
search(path: string, method: HttpMethod): {
|
|
17
18
|
path: string;
|
|
18
|
-
handler:
|
|
19
|
+
handler: any;
|
|
19
20
|
pattern: string;
|
|
20
21
|
} | null;
|
|
21
22
|
}
|
package/dist/trie.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var L=Object.create;var{getPrototypeOf:O,defineProperty:B,getOwnPropertyNames:G,getOwnPropertyDescriptor:P}=Object,H=Object.prototype.hasOwnProperty;var Q=(f,j,b)=>{b=f!=null?L(O(f)):{};let q=j||!f||!f.__esModule?B(b,"default",{value:f,enumerable:!0}):b;for(let v of G(f))if(!H.call(q,v))B(q,v,{get:()=>f[v],enumerable:!0});return q},F=new WeakMap,R=(f)=>{var j=F.get(f),b;if(j)return j;if(j=B({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")G(f).map((q)=>!H.call(j,q)&&B(j,q,{get:()=>f[q],enumerable:!(b=P(f,q))||b.enumerable}));return F.set(f,j),j},U=(f,j)=>()=>(j||f((j={exports:{}}).exports,j),j.exports);var V=(f,j)=>{for(var b in j)B(f,b,{get:j[b],enumerable:!0,configurable:!0,set:(q)=>j[b]=()=>q})};var W=(f,j)=>()=>(f&&(j=f(f=0)),j);var X=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(j,b)=>(typeof require!=="undefined"?require:j)[b]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});class C{children;isEndOfWord;handler;isDynamic;pattern;path;method;constructor(){this.children={},this.isEndOfWord=!1,this.handler=[],this.isDynamic=!1,this.pattern="",this.path="",this.method=[]}}class J{root;constructor(){this.root=new C}pushMidl(f,...j){let b=this.root,q=f.split("/").filter(Boolean);if(f==="/"){b.handler.push(...j);return}for(let v of q){let z=v;if(v.startsWith(":"))z=":";if(!b.children[z])b.children[z]=new C;b=b.children[z]}b.handler.push(...j)}insert(f,j){let b=this.root,q=f.split("/").filter(Boolean);if(f==="/"){b.isEndOfWord=!0,b.handler.push(j.handler),b.path=f,b.method.push(j.method);return}for(let v of q){let z=!1,A=v;if(v.startsWith(":"))z=!0,A=":";if(!b.children[A])b.children[A]=new C;b=b.children[A],b.isDynamic=z,b.pattern=v}b.isEndOfWord=!0,b.path=f,b.method.push(j.method),b.handler.push(j.handler)}search(f,j){let b=this.root,q=f.split("/").filter(Boolean),v=q.length;for(let K of q){let E=K;if(!b.children[E])if(b.children[":"])b=b.children[":"];else return null;else b=b.children[E]}let z=b.path.split("/").filter(Boolean);if(v!==z.length)return null;if(b.method.indexOf(j)!==-1)return{path:b.path,handler:b.handler[0],pattern:b.pattern};return null}}export{J as default};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BunRequest, Server } from "bun";
|
|
2
2
|
export type listenCalllBackType = () => void;
|
|
3
|
-
export type handlerFunction = (ctx: ContextType
|
|
4
|
-
export type middlewareFunc = (ctx: ContextType | BunRequest, server
|
|
3
|
+
export type handlerFunction = (ctx: ContextType) => Response | Promise<Response | undefined>;
|
|
4
|
+
export type middlewareFunc = (ctx: ContextType | BunRequest, server: Server) => void | Response | Promise<undefined | Response>;
|
|
5
5
|
export type HookFunction = (ctx: ContextType, result?: Response | null, server?: Server) => void | null | Response | Promise<void | null | Response>;
|
|
6
6
|
export type RouteNotFoundHandler = (ctx: ContextType) => Promise<Response>;
|
|
7
7
|
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD" | "ANY" | "PROPFIND";
|
|
@@ -59,7 +59,7 @@ export interface CookieOptions {
|
|
|
59
59
|
}
|
|
60
60
|
export interface RouteHandlerT {
|
|
61
61
|
method: string;
|
|
62
|
-
handler:
|
|
62
|
+
handler: handlerFunction;
|
|
63
63
|
isDynamic?: boolean;
|
|
64
64
|
path?: string;
|
|
65
65
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* URL utility.
|
|
4
|
+
*/
|
|
5
|
+
export type Pattern = readonly [string, string, RegExp | true] | '*';
|
|
6
|
+
export declare const splitPath: (path: string) => string[];
|
|
7
|
+
export declare const splitRoutingPath: (routePath: string) => string[];
|
|
8
|
+
export declare const getPattern: (label: string, next?: string) => Pattern | null;
|
|
9
|
+
type Decoder = (str: string) => string;
|
|
10
|
+
export declare const tryDecode: (str: string, decoder: Decoder) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Try to apply decodeURI() to given string.
|
|
13
|
+
* If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
|
|
14
|
+
* @param str The string to decode.
|
|
15
|
+
* @returns The decoded string that sometimes contains undecodable percent encoding.
|
|
16
|
+
* @example
|
|
17
|
+
* tryDecodeURI('Hello%20World') // 'Hello World'
|
|
18
|
+
* tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
|
|
19
|
+
*/
|
|
20
|
+
export declare const tryDecodeURI: (str: string) => string;
|
|
21
|
+
export declare const getPath: (url: string) => string;
|
|
22
|
+
export declare const getQueryStrings: (url: string) => string;
|
|
23
|
+
export declare const getPathNoStrict: (request: Request) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Merge paths.
|
|
26
|
+
* @param {string[]} ...paths - The paths to merge.
|
|
27
|
+
* @returns {string} The merged path.
|
|
28
|
+
* @example
|
|
29
|
+
* mergePath('/api', '/users') // '/api/users'
|
|
30
|
+
* mergePath('/api/', '/users') // '/api/users'
|
|
31
|
+
* mergePath('/api', '/') // '/api'
|
|
32
|
+
* mergePath('/api/', '/') // '/api/'
|
|
33
|
+
*/
|
|
34
|
+
export declare const mergePath: (...paths: string[]) => string;
|
|
35
|
+
export declare const checkOptionalParameter: (path: string) => string[] | null;
|
|
36
|
+
export declare const getQueryParam: (url: string, key?: string) => string | undefined | Record<string, string>;
|
|
37
|
+
export declare const getQueryParams: (url: string, key?: string) => string[] | undefined | Record<string, string[]>;
|
|
38
|
+
export declare const decodeURIComponent_: typeof decodeURIComponent;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var $=(z)=>{let A=z.split("/");if(A[0]==="")A.shift();return A},Q=(z)=>{let{groups:A,path:E}=B(z),J=$(E);return F(J,A)},B=(z)=>{let A=[];return z=z.replace(/\{[^}]+\}/g,(E,J)=>{let H=`@${J}`;return A.push([H,E]),H}),{groups:A,path:z}},F=(z,A)=>{for(let E=A.length-1;E>=0;E--){let[J]=A[E];for(let H=z.length-1;H>=0;H--)if(z[H].includes(J)){z[H]=z[H].replace(J,A[E][1]);break}}return z},W={},f=(z,A)=>{if(z==="*")return"*";let E=z.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(E){let J=`${z}#${A}`;if(!W[J])if(E[2])W[J]=A&&A[0]!==":"&&A[0]!=="*"?[J,E[1],new RegExp(`^${E[2]}(?=/${A})`)]:[z,E[1],new RegExp(`^${E[2]}$`)];else W[J]=[z,E[1],!0];return W[J]}return null},Y=(z,A)=>{try{return A(z)}catch{return z.replace(/(?:%[0-9A-Fa-f]{2})+/g,(E)=>{try{return A(E)}catch{return E}})}},M=(z)=>Y(z,decodeURI),S=(z)=>{let A=z.indexOf("/",z.indexOf(":")+4),E=A;for(;E<z.length;E++){let J=z.charCodeAt(E);if(J===37){let H=z.indexOf("?",E),N=z.slice(A,H===-1?void 0:H);return M(N.includes("%25")?N.replace(/%25/g,"%2525"):N)}else if(J===63)break}return z.slice(A,E)},D=(z)=>{let A=z.indexOf("?",8);return A===-1?"":"?"+z.slice(A+1)},j=(z)=>{let A=S(z.url);return A.length>1&&A.at(-1)==="/"?A.slice(0,-1):A},w=(z,A,...E)=>{if(E.length)A=w(A,...E);return`${z?.[0]==="/"?"":"/"}${z}${A==="/"?"":`${z?.at(-1)==="/"?"":"/"}${A?.[0]==="/"?A.slice(1):A}`}`},R=(z)=>{if(z.charCodeAt(z.length-1)!==63||!z.includes(":"))return null;let A=z.split("/"),E=[],J="";return A.forEach((H)=>{if(H!==""&&!/\:/.test(H))J+="/"+H;else if(/\:/.test(H))if(/\?/.test(H)){if(E.length===0&&J==="")E.push("/");else E.push(J);let N=H.replace("?","");J+="/"+N,E.push(J)}else J+="/"+H}),E.filter((H,N,L)=>L.indexOf(H)===N)},X=(z)=>{if(!/[%+]/.test(z))return z;if(z.indexOf("+")!==-1)z=z.replace(/\+/g," ");return z.indexOf("%")!==-1?Y(z,G):z},Z=(z,A,E)=>{let J;if(!E&&A&&!/[%+]/.test(A)){let L=z.indexOf(`?${A}`,8);if(L===-1)L=z.indexOf(`&${A}`,8);while(L!==-1){let T=z.charCodeAt(L+A.length+1);if(T===61){let O=L+A.length+2,V=z.indexOf("&",O);return X(z.slice(O,V===-1?void 0:V))}else if(T==38||isNaN(T))return"";L=z.indexOf(`&${A}`,L+1)}if(J=/[%+]/.test(z),!J)return}let H={};J??=/[%+]/.test(z);let N=z.indexOf("?",8);while(N!==-1){let L=z.indexOf("&",N+1),T=z.indexOf("=",N);if(T>L&&L!==-1)T=-1;let O=z.slice(N+1,T===-1?L===-1?void 0:L:T);if(J)O=X(O);if(N=L,O==="")continue;let V;if(T===-1)V="";else if(V=z.slice(T+1,L===-1?void 0:L),J)V=X(V);if(E){if(!(H[O]&&Array.isArray(H[O])))H[O]=[];H[O].push(V)}else H[O]??=V}return A?H[A]:H},U=Z,q=(z,A)=>{return Z(z,A,!0)},G=decodeURIComponent;export{M as tryDecodeURI,Y as tryDecode,Q as splitRoutingPath,$ as splitPath,w as mergePath,D as getQueryStrings,q as getQueryParams,U as getQueryParam,f as getPattern,j as getPathNoStrict,S as getPath,G as decodeURIComponent_,R as checkOptionalParameter};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diesel-core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.9",
|
|
4
4
|
"description": "Web framework built on Web Standards",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -40,31 +40,31 @@
|
|
|
40
40
|
"import": "./dist/middlewares/ratelimit/rate-limit.js",
|
|
41
41
|
"require": "./dist/middlewares/ratelimit/rate-limit.js"
|
|
42
42
|
},
|
|
43
|
-
"./redisStore":{
|
|
43
|
+
"./redisStore": {
|
|
44
44
|
"types": "./dist/middlewares/ratelimit/implementation.d.ts",
|
|
45
45
|
"import": "./dist/middlewares/ratelimit/implementation.js",
|
|
46
46
|
"require": "./dist/middlewares/ratelimit/implementation.js"
|
|
47
47
|
},
|
|
48
|
-
"./dicedbStore":{
|
|
48
|
+
"./dicedbStore": {
|
|
49
49
|
"types": "./dist/middlewares/ratelimit/implementation.d.ts",
|
|
50
50
|
"import": "./dist/middlewares/ratelimit/implementation.js",
|
|
51
51
|
"require": "./dist/middlewares/ratelimit/implementation.js"
|
|
52
52
|
},
|
|
53
|
-
"./jwt":{
|
|
53
|
+
"./jwt": {
|
|
54
54
|
"types": "./dist/middlewares/jwt/index.d.ts",
|
|
55
55
|
"import": "./dist/middlewares/jwt/index.js",
|
|
56
|
-
"require": "./dist/middlewares/jwt/index.js"
|
|
56
|
+
"require": "./dist/middlewares/jwt/index.js"
|
|
57
57
|
},
|
|
58
|
-
"./powered-by":{
|
|
58
|
+
"./powered-by": {
|
|
59
59
|
"types": "./dist/middlewares/powered-by/index.d.ts",
|
|
60
60
|
"import": "./dist/middlewares/powered-by/index.js",
|
|
61
|
-
"require": "./dist/middlewares/powered-by/index.js"
|
|
61
|
+
"require": "./dist/middlewares/powered-by/index.js"
|
|
62
62
|
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
"./requestid": {
|
|
64
|
+
"types": "./dist/middlewares/request-id/index.d.ts",
|
|
65
|
+
"import": "./dist/middlewares/request-id/index.js",
|
|
66
|
+
"require": "./dist/middlewares/request-id/index.js"
|
|
67
|
+
}
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "bun run build.js",
|