diesel-core 1.6.7 → 1.6.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.
@@ -1,5 +1,6 @@
1
+ import * as http from 'node:http';
1
2
  export interface options {
2
3
  fetch: (req: Request, ...args: any) => Response | Promise<Response>;
3
4
  port: number;
4
5
  }
5
- export declare function serve(options: options): void;
6
+ export declare function serve(options: options): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
@@ -89,6 +89,7 @@ function sendWebResToNodeRes(webRes, nodeRes) {
89
89
  }
90
90
  function serve(options) {
91
91
  var _this = this;
92
+ var _a;
92
93
  var server = http.createServer(function (request, response) { return __awaiter(_this, void 0, void 0, function () {
93
94
  var webRequest, webRes;
94
95
  return __generator(this, function (_a) {
@@ -106,5 +107,6 @@ function serve(options) {
106
107
  }
107
108
  });
108
109
  }); });
109
- server.listen(options.port, function () { return console.log('node server running on port 3000'); });
110
+ server.listen((_a = options.port) !== null && _a !== void 0 ? _a : 3000, function () { var _a; return console.log("node server running on port ".concat((_a = options.port) !== null && _a !== void 0 ? _a : 3000)); });
111
+ return server;
110
112
  }
@@ -0,0 +1,11 @@
1
+ export const supportedMethods = [
2
+ "GET",
3
+ "POST",
4
+ "PUT",
5
+ "PATCH",
6
+ "DELETE",
7
+ "ANY",
8
+ "HEAD",
9
+ "OPTIONS",
10
+ "PROPFIND",
11
+ ];
package/dist/ctx.js CHANGED
@@ -1,54 +1,509 @@
1
- var U1=Object.create;var{getPrototypeOf:W1,defineProperty:X,getOwnPropertyNames:u,getOwnPropertyDescriptor:M1}=Object,_=Object.prototype.hasOwnProperty;var H1=(f,v,g)=>{g=f!=null?U1(W1(f)):{};let A=v||!f||!f.__esModule?X(g,"default",{value:f,enumerable:!0}):g;for(let C of u(f))if(!_.call(A,C))X(A,C,{get:()=>f[C],enumerable:!0});return A},S=new WeakMap,q1=(f)=>{var v=S.get(f),g;if(v)return v;if(v=X({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")u(f).map((A)=>!_.call(v,A)&&X(v,A,{get:()=>f[A],enumerable:!(g=M1(f,A))||g.enumerable}));return S.set(f,v),v},D=(f,v)=>()=>(v||f((v={exports:{}}).exports,v),v.exports);var F1=(f,v)=>{for(var g in v)X(f,g,{get:v[g],enumerable:!0,configurable:!0,set:(A)=>v[g]=()=>A})};var D1=(f,v)=>()=>(f&&(v=f(f=0)),v);var y1=((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 p={};F1(p,{sep:()=>s,resolve:()=>M,relative:()=>h,posix:()=>o,parse:()=>e,normalize:()=>y,join:()=>T,isAbsolute:()=>r,format:()=>i,extname:()=>n,dirname:()=>m,delimiter:()=>a,default:()=>L1,basename:()=>l,_makeLong:()=>d});function V(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function c(f,v){var g="",A=0,C=-1,b=0,w;for(var j=0;j<=f.length;++j){if(j<f.length)w=f.charCodeAt(j);else if(w===47)break;else w=47;if(w===47){if(C===j-1||b===1);else if(C!==j-1&&b===2){if(g.length<2||A!==2||g.charCodeAt(g.length-1)!==46||g.charCodeAt(g.length-2)!==46){if(g.length>2){var K=g.lastIndexOf("/");if(K!==g.length-1){if(K===-1)g="",A=0;else g=g.slice(0,K),A=g.length-1-g.lastIndexOf("/");C=j,b=0;continue}}else if(g.length===2||g.length===1){g="",A=0,C=j,b=0;continue}}if(v){if(g.length>0)g+="/..";else g="..";A=2}}else{if(g.length>0)g+="/"+f.slice(C+1,j);else g=f.slice(C+1,j);A=j-C-1}C=j,b=0}else if(w===46&&b!==-1)++b;else b=-1}return g}function R1(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(V(C),C.length===0)continue;f=C+"/"+f,v=C.charCodeAt(0)===47}if(f=c(f,!v),v)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function y(f){if(V(f),f.length===0)return".";var v=f.charCodeAt(0)===47,g=f.charCodeAt(f.length-1)===47;if(f=c(f,!v),f.length===0&&!v)f=".";if(f.length>0&&g)f+="/";if(v)return"/"+f;return f}function r(f){return V(f),f.length>0&&f.charCodeAt(0)===47}function T(){if(arguments.length===0)return".";var f;for(var v=0;v<arguments.length;++v){var g=arguments[v];if(V(g),g.length>0)if(f===void 0)f=g;else f+="/"+g}if(f===void 0)return".";return y(f)}function h(f,v){if(V(f),V(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,b=1;for(;b<v.length;++b)if(v.charCodeAt(b)!==47)break;var w=v.length,j=w-b,K=C<j?C:j,Y=-1,z=0;for(;z<=K;++z){if(z===K){if(j>K){if(v.charCodeAt(b+z)===47)return v.slice(b+z+1);else if(z===0)return v.slice(b+z)}else if(C>K){if(f.charCodeAt(g+z)===47)Y=z;else if(z===0)Y=0}break}var Q=f.charCodeAt(g+z),G=v.charCodeAt(b+z);if(Q!==G)break;else if(Q===47)Y=z}var B="";for(z=g+Y+1;z<=A;++z)if(z===A||f.charCodeAt(z)===47)if(B.length===0)B+="..";else B+="/..";if(B.length>0)return B+v.slice(b+Y);else{if(b+=Y,v.charCodeAt(b)===47)++b;return v.slice(b)}}function d(f){return f}function m(f){if(V(f),f.length===0)return".";var v=f.charCodeAt(0),g=v===47,A=-1,C=!0;for(var b=f.length-1;b>=1;--b)if(v=f.charCodeAt(b),v===47){if(!C){A=b;break}}else C=!1;if(A===-1)return g?"/":".";if(g&&A===1)return"//";return f.slice(0,A)}function l(f,v){if(v!==void 0&&typeof v!=="string")throw new TypeError('"ext" argument must be a string');V(f);var g=0,A=-1,C=!0,b;if(v!==void 0&&v.length>0&&v.length<=f.length){if(v.length===f.length&&v===f)return"";var w=v.length-1,j=-1;for(b=f.length-1;b>=0;--b){var K=f.charCodeAt(b);if(K===47){if(!C){g=b+1;break}}else{if(j===-1)C=!1,j=b+1;if(w>=0)if(K===v.charCodeAt(w)){if(--w===-1)A=b}else w=-1,A=j}}if(g===A)A=j;else if(A===-1)A=f.length;return f.slice(g,A)}else{for(b=f.length-1;b>=0;--b)if(f.charCodeAt(b)===47){if(!C){g=b+1;break}}else if(A===-1)C=!1,A=b+1;if(A===-1)return"";return f.slice(g,A)}}function n(f){V(f);var v=-1,g=0,A=-1,C=!0,b=0;for(var w=f.length-1;w>=0;--w){var j=f.charCodeAt(w);if(j===47){if(!C){g=w+1;break}continue}if(A===-1)C=!1,A=w+1;if(j===46){if(v===-1)v=w;else if(b!==1)b=1}else if(v!==-1)b=-1}if(v===-1||A===-1||b===0||b===1&&v===A-1&&v===g+1)return"";return f.slice(v,A)}function i(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 e(f){V(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 b=-1,w=0,j=-1,K=!0,Y=f.length-1,z=0;for(;Y>=C;--Y){if(g=f.charCodeAt(Y),g===47){if(!K){w=Y+1;break}continue}if(j===-1)K=!1,j=Y+1;if(g===46){if(b===-1)b=Y;else if(z!==1)z=1}else if(b!==-1)z=-1}if(b===-1||j===-1||z===0||z===1&&b===j-1&&b===w+1){if(j!==-1)if(w===0&&A)v.base=v.name=f.slice(1,j);else v.base=v.name=f.slice(w,j)}else{if(w===0&&A)v.name=f.slice(1,b),v.base=f.slice(1,j);else v.name=f.slice(w,b),v.base=f.slice(w,j);v.ext=f.slice(b,j)}if(w>0)v.dir=f.slice(0,w-1);else if(A)v.dir="/";return v}var s="/",a=":",o,L1;var t=D1(()=>{o=((f)=>(f.posix=f,f))({resolve:M,normalize:y,isAbsolute:r,join:T,relative:h,_makeLong:d,dirname:m,basename:l,extname:n,format:i,parse:e,sep:s,delimiter:a,win32:null,posix:null}),L1=o});var v1=D((S1)=>{var O1=/[|\\{}()[\]^$+*?.]/g,N1=Object.prototype.hasOwnProperty,L=function(f,v){return N1.apply(f,[v])};S1.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(O1,"\\$&")};var x1={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&#34;","'":"&#39;"},k1=/[&<>'"]/g;function I1(f){return x1[f]||f}var E1=`var _ENCODE_HTML_RULES = {
2
- "&": "&amp;"
3
- , "<": "&lt;"
4
- , ">": "&gt;"
5
- , '"': "&#34;"
6
- , "'": "&#39;"
7
- }
8
- , _MATCH_HTML = /[&<>'"]/g;
9
- function encode_char(c) {
10
- return _ENCODE_HTML_RULES[c] || c;
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
11
9
  };
12
- `;S1.escapeXML=function(f){return f==null?"":String(f).replace(k1,I1)};function f1(){return Function.prototype.toString.call(this)+`;
13
- `+E1}try{if(typeof Object.defineProperty==="function")Object.defineProperty(S1.escapeXML,"toString",{value:f1});else S1.escapeXML.toString=f1}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}S1.shallowCopy=function(f,v){if(v=v||{},f!==null&&f!==void 0)for(var g in v){if(!L(v,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=v[g]}return f};S1.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(!L(v,C))continue;if(C==="__proto__"||C==="constructor")continue;f[C]=v[C]}}return f};S1.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={}}};S1.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(v){return v[1].toUpperCase()})};S1.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{}}}();S1.hasOwnOnlyObject=function(f){var v=S1.createNullProtoObjWherePossible();for(var g in f)if(L(f,g))v[g]=f[g];return v}});var A1=D((G0,h1)=>{h1.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 G1=D(($1)=>{var x=(()=>({})),U=(t(),q1(p)),Z=v1(),C1=!1,d1=A1().version,m1="<",l1=">",n1="%",Y1="locals",i1="ejs",e1="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",Z1=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],s1=Z1.concat("cache"),b1=/^\uFEFF/,O=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;$1.cache=Z.cache;$1.fileLoader=x.readFileSync;$1.localsName=Y1;$1.promiseImpl=new Function("return this;")().Promise;$1.resolveInclude=function(f,v,g){var{dirname:A,extname:C,resolve:b}=U,w=b(g?v:A(v),f),j=C(f);if(!j)w+=".ejs";return w};function w1(f,v){var g;if(v.some(function(A){return g=$1.resolveInclude(f,A,!0),x.existsSync(g)}))return g}function a1(f,v){var g,A,C=v.views,b=/^[A-Za-z]+:\\|^\//.exec(f);if(b&&b.length)if(f=f.replace(/^\/*/,""),Array.isArray(v.root))g=w1(f,v.root);else g=$1.resolveInclude(f,v.root||"/",!0);else{if(v.filename){if(A=$1.resolveInclude(f,v.filename),x.existsSync(A))g=A}if(!g&&Array.isArray(C))g=w1(f,C);if(!g&&typeof v.includer!=="function")throw new Error('Could not find the include file "'+v.escapeFunction(f)+'"')}return g}function W(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=$1.cache.get(A),g)return g;if(!C)v=j1(A).toString().replace(b1,"")}else if(!C){if(!A)throw new Error("Internal EJS error: no file name or template provided");v=j1(A).toString().replace(b1,"")}if(g=$1.compile(v,f),f.cache)$1.cache.set(A,g);return g}function o1(f,v,g){var A;if(!g)if(typeof $1.promiseImpl=="function")return new $1.promiseImpl(function(C,b){try{A=W(f)(v),C(A)}catch(w){b(w)}});else throw new Error("Please provide a callback function");else{try{A=W(f)(v)}catch(C){return g(C)}g(null,A)}}function j1(f){return $1.fileLoader(f)}function p1(f,v){var g=Z.shallowCopy(Z.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 W(g,A.template)}}return W(g)}function z1(f,v,g,A,C){var b=v.split(`
14
- `),w=Math.max(A-3,0),j=Math.min(b.length,A+3),K=C(g),Y=b.slice(w,j).map(function(z,Q){var G=Q+w+1;return(G==A?" >> ":" ")+G+"| "+z}).join(`
15
- `);throw f.path=K,f.message=(K||"ejs")+":"+A+`
16
- `+Y+`
17
-
18
- `+f.message,f}function K1(f){return f.replace(/;(\s*$)/,"$1")}$1.compile=function f(v,g){var A;if(g&&g.scope){if(!C1)console.warn("`scope` option is deprecated and will be removed in EJS 3"),C1=!0;if(!g.context)g.context=g.scope;delete g.scope}return A=new $(v,g),A.compile()};$1.render=function(f,v,g){var A=v||Z.createNullProtoObjWherePossible(),C=g||Z.createNullProtoObjWherePossible();if(arguments.length==2)Z.shallowCopyFromList(C,A,Z1);return W(C,f)(A)};$1.renderFile=function(){var f=Array.prototype.slice.call(arguments),v=f.shift(),g,A={filename:v},C,b;if(typeof arguments[arguments.length-1]=="function")g=f.pop();if(f.length){if(C=f.shift(),f.length)Z.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(b=C.settings["view options"],b)Z.shallowCopy(A,b)}Z.shallowCopyFromList(A,C,s1)}A.filename=v}else C=Z.createNullProtoObjWherePossible();return o1(A,C,g)};$1.Template=$;$1.clearCache=function(){$1.cache.reset()};function $(f,v){var g=Z.hasOwnOnlyObject(v),A=Z.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||Z.escapeXML,A.compileDebug=g.compileDebug!==!1,A.debug=!!g.debug,A.filename=g.filename,A.openDelimiter=g.openDelimiter||$1.openDelimiter||m1,A.closeDelimiter=g.closeDelimiter||$1.closeDelimiter||l1,A.delimiter=g.delimiter||$1.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||$1.localsName||Y1,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()}$.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};$.prototype={createRegex:function(){var f=e1,v=Z.escapeRegExpChars(this.opts.delimiter),g=Z.escapeRegExpChars(this.opts.openDelimiter),A=Z.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="",b=g.escapeFunction,w,j=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(!O.test(g.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");A+=" var "+g.outputFunctionName+` = __append;
21
- `}if(g.localsName&&!O.test(g.localsName))throw new Error("localsName is not a valid JS identifier.");if(g.destructuredLocals&&g.destructuredLocals.length){var K=" var __locals = ("+g.localsName+` || {}),
22
- `;for(var Y=0;Y<g.destructuredLocals.length;Y++){var z=g.destructuredLocals[Y];if(!O.test(z))throw new Error("destructuredLocals["+Y+"] is not a valid JS identifier.");if(Y>0)K+=`,
23
- `;K+=z+" = __locals."+z}A+=K+`;
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 = `+j+`;
30
- try {
31
- `+this.source+`} catch (e) {
32
- rethrow(e, __lines, __filename, __line, escapeFn);
10
+ import { getMimeType } from "./utils/mimeType";
11
+ let ejsInstance = null;
12
+ function getEjs() {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ if (!ejsInstance) {
15
+ const mod = yield import("ejs");
16
+ ejsInstance = mod.default || mod;
17
+ }
18
+ return ejsInstance;
19
+ });
33
20
  }
34
- `;else f=this.source;if(g.client){if(f="escapeFn = escapeFn || "+b.toString()+`;
35
- `+f,g.compileDebug)f="rethrow = rethrow || "+z1.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=`+j+`
39
- `;try{if(g.async)try{w=new Function("return (async function(){}).constructor;")()}catch(J){if(J instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw J}else w=Function;v=new w(g.localsName+", escapeFn, include, rethrow",f)}catch(J){if(J instanceof SyntaxError){if(g.filename)J.message+=" in "+g.filename;if(J.message+=` while compiling ejs
40
-
41
- `,J.message+=`If the above error is not helpful, you may want to try EJS-Lint:
42
- `,J.message+="https://github.com/RyanZim/EJS-Lint",!g.async)J.message+=`
43
- `,J.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw J}var Q=g.client?v:function J(I){var B1=function(X1,E){var F=Z.shallowCopy(Z.createNullProtoObjWherePossible(),I);if(E)F=Z.shallowCopy(F,E);return p1(X1,g)(F)};return v.apply(g.context,[I||Z.createNullProtoObjWherePossible(),b,B1,z1])};if(g.filename&&typeof Object.defineProperty==="function"){var G=g.filename,B=U.basename(G,U.extname(G));try{Object.defineProperty(Q,"name",{value:B,writable:!1,enumerable:!1,configurable:!0})}catch(J){}}return Q},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,b=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(w,j){var K;if(w.indexOf(C+A)===0&&w.indexOf(C+A+A)!==0){if(K=g[j+2],!(K==A+b||K=="-"+A+b||K=="_"+A+b))throw new Error('Could not find matching close tag for "'+w+'".')}v.scanLine(w)})},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,b=0;switch(b=f.split(`
46
- `).length-1,f){case A+g:case A+g+"_":this.mode=$.modes.EVAL;break;case A+g+"=":this.mode=$.modes.ESCAPED;break;case A+g+"-":this.mode=$.modes.RAW;break;case A+g+"#":this.mode=$.modes.COMMENT;break;case A+g+g:this.mode=$.modes.LITERAL,this.source+=' ; __append("'+f.replace(A+g+g,A+g)+`")
47
- `;break;case g+g+C:this.mode=$.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==$.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 $.modes.EVAL:case $.modes.ESCAPED:case $.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
49
- `))f+=`
50
- `}switch(this.mode){case $.modes.EVAL:this.source+=" ; "+f+`
51
- `;break;case $.modes.ESCAPED:this.source+=" ; __append(escapeFn("+K1(f)+`))
52
- `;break;case $.modes.RAW:this.source+=" ; __append("+K1(f)+`)
53
- `;break;case $.modes.COMMENT:break;case $.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(v.opts.compileDebug&&b)this.currentLine+=b,this.source+=" ; __line = "+this.currentLine+`
54
- `}};$1.escapeXML=Z.escapeXML;$1.__express=$1.renderFile;$1.VERSION=d1;$1.name=i1;if(typeof window!="undefined")window.ejs=$1});function P(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(() => H1(G1(),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"};class K0{req;server;path;routePattern;paramNames;env;executionContext;headers=new Headers;parsedQuery=null;parsedParams=null;parsedCookies=null;parsedBody=null;contextData={};urlObject=null;constructor(f,v,g,A,C,b,w){this.req=f,this.server=v,this.path=g,this.routePattern=A,this.executionContext=w,this.env=b,this.paramNames=C}setHeader(f,v){return this.headers.set(f,v),this}removeHeader(f){return this.headers.delete(f),this}set(f,v){return this.contextData[f]=v,this}get(f){return this.contextData[f]}get ip(){if(this.server)return this.server.requestIP(this.req)?.address??null;return this.req.headers.get("CF-Connecting-IP")||null}get url(){if(!this.urlObject)this.urlObject=new URL(this.req.url);return this.urlObject}get query(){if(!this.parsedQuery)this.parsedQuery=this.url.search?Object.fromEntries(this.url.searchParams):{};return this.parsedQuery}get params(){if(!Array.isArray(this.paramNames))return this.paramNames;if(!this.parsedParams)try{this.parsedParams=Z0(this.paramNames,this.path)}catch(f){let v=f instanceof Error?f.message:String(f);throw new Error(`Failed to extract route parameters: ${v}`)}return this.parsedParams??{}}get body(){if(this.req.method==="GET")return Promise.resolve({});if(!this.parsedBody)this.parsedBody=(async()=>{try{let f=await $0(this.req);if(f.error)throw new Error(f.error);return Object.keys(f).length===0?null:f}catch(f){throw new Error("Invalid request body format")}})();return this.parsedBody}text(f,v=200){return new Response(f,{status:v,headers:this.headers})}send(f,v=200){let g;if(f instanceof Uint8Array)g="Uint8Array";else if(f instanceof ArrayBuffer)g="ArrayBuffer";else g=typeof f;if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",z0[g]??"text/plain; charset=utf-8");let A=g==="object"&&f!==null?JSON.stringify(f):f;return new Response(A,{status:v,headers:this.headers})}json(f,v=200){return Response.json(f,{status:v,headers:this.headers})}file(f,v,g=200){let A=Bun.file(f);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",v??P(f));return new Response(A,{status:g,headers:this.headers})}async ejs(f,v={},g=200){let A=await j0();try{let C=await Bun.file(f).text(),b=A.render(C,v),w=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(b,{status:g,headers:w})}catch(C){return console.error("EJS Rendering Error:",C),new Response("Error rendering template",{status:500})}}redirect(f,v=302){return this.headers.set("Location",f),new Response(null,{status:v,headers:this.headers})}setCookie(f,v,g={}){let A=`${encodeURIComponent(f)}=${encodeURIComponent(v)}`;if(g.maxAge)A+=`; Max-Age=${g.maxAge}`;if(g.expires)A+=`; Expires=${g.expires.toUTCString()}`;if(g.path)A+=`; Path=${g.path}`;if(g.domain)A+=`; Domain=${g.domain}`;if(g.secure)A+="; Secure";if(g.httpOnly)A+="; HttpOnly";if(g.sameSite)A+=`; SameSite=${g.sameSite}`;return this.headers.append("Set-Cookie",A),this}get cookies(){if(!this.parsedCookies){let f=this.req.headers.get("cookie");this.parsedCookies=f?Y0(f):{}}return this.parsedCookies}stream(f){let v=new Headers(this.headers),g=new ReadableStream({async start(A){await f(A),A.close()}});return new Response(g,{headers:v})}yieldStream(f){return new Response}}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]=v.split("?"),C=A.split("/").filter((w)=>w!==""),b=C.length-f.length;for(let w=0;w<f.length;w++)g[f[w]]=C[b+w];return g}function H0(f,v){let g={},A=f.split("/"),[C]=v.split("?"),b=C.split("/");if(A.length!==b.length)return null;for(let w=0;w<A.length;w++){let j=A[w];if(j.charCodeAt(0)===58)g[j.slice(1)]=b[w]}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[b,w]of A.entries())C[b]=w;return C}return{error:"Unknown request body type"}}export{Z0 as extractParam,H0 as extractDynamicParams,K0 as Context};
21
+ const typeMap = {
22
+ string: "text/plain; charset=utf-8",
23
+ object: "application/json; charset=utf-8",
24
+ Uint8Array: "application/octet-stream",
25
+ ArrayBuffer: "application/octet-stream",
26
+ };
27
+ export class Context {
28
+ constructor(req, server, path, routePattern, paramNames, env, executionContext) {
29
+ this.headers = new Headers();
30
+ // Lazily initialized
31
+ this.parsedQuery = null;
32
+ this.parsedParams = null;
33
+ this.parsedCookies = null;
34
+ this.parsedBody = null;
35
+ this.contextData = {};
36
+ this.urlObject = null;
37
+ this.req = req;
38
+ this.server = server;
39
+ this.path = path;
40
+ this.routePattern = routePattern;
41
+ this.executionContext = executionContext;
42
+ this.env = env;
43
+ this.paramNames = paramNames;
44
+ }
45
+ // Methods
46
+ setHeader(key, value) {
47
+ this.headers.set(key, value);
48
+ return this;
49
+ }
50
+ removeHeader(key) {
51
+ this.headers.delete(key);
52
+ return this;
53
+ }
54
+ set(key, value) {
55
+ this.contextData[key] = value;
56
+ return this;
57
+ }
58
+ get(key) {
59
+ return this.contextData[key];
60
+ }
61
+ get ip() {
62
+ var _a, _b;
63
+ if (this.server)
64
+ return (_b = (_a = this.server.requestIP(this.req)) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : null;
65
+ return this.req.headers.get("CF-Connecting-IP") || null;
66
+ }
67
+ get url() {
68
+ if (!this.urlObject) {
69
+ this.urlObject = new URL(this.req.url);
70
+ }
71
+ return this.urlObject;
72
+ }
73
+ get query() {
74
+ if (!this.parsedQuery) {
75
+ this.parsedQuery = this.url.search ? Object.fromEntries(this.url.searchParams) : {};
76
+ }
77
+ return this.parsedQuery;
78
+ }
79
+ get params() {
80
+ var _a;
81
+ if (!Array.isArray(this.paramNames)) {
82
+ return this.paramNames;
83
+ }
84
+ if (!this.parsedParams) {
85
+ try {
86
+ this.parsedParams = extractParam(this.paramNames, this.path);
87
+ }
88
+ catch (error) {
89
+ const message = error instanceof Error ? error.message : String(error);
90
+ throw new Error(`Failed to extract route parameters: ${message}`);
91
+ }
92
+ }
93
+ return (_a = this.parsedParams) !== null && _a !== void 0 ? _a : {};
94
+ }
95
+ get body() {
96
+ if (this.req.method === "GET") {
97
+ return Promise.resolve({});
98
+ }
99
+ if (!this.parsedBody) {
100
+ this.parsedBody = (() => __awaiter(this, void 0, void 0, function* () {
101
+ try {
102
+ const result = yield parseBody(this.req);
103
+ if (result.error) {
104
+ throw new Error(result.error);
105
+ }
106
+ return Object.keys(result).length === 0 ? null : result;
107
+ }
108
+ catch (error) {
109
+ throw new Error("Invalid request body format");
110
+ // const message = error instanceof Error ? error.message : String(error);
111
+ // throw new Error(`Failed to parse request body: ${message}`);
112
+ }
113
+ }))();
114
+ }
115
+ return this.parsedBody;
116
+ }
117
+ text(data, status = 200) {
118
+ // if (!this.headers.has("Content-Type")) {
119
+ // this.headers.set("Content-Type", "text/plain; charset=utf-8");
120
+ // }
121
+ return new Response(data, {
122
+ status,
123
+ headers: this.headers
124
+ });
125
+ }
126
+ send(data, status = 200) {
127
+ // this.status = status;
128
+ var _a;
129
+ // const dataType = data instanceof Uint8Array ? "Uint8Array"
130
+ // : data instanceof ArrayBuffer ? "ArrayBuffer"
131
+ // : typeof data;
132
+ let dataType;
133
+ if (data instanceof Uint8Array)
134
+ dataType = "Uint8Array";
135
+ else if (data instanceof ArrayBuffer)
136
+ dataType = 'ArrayBuffer';
137
+ else
138
+ dataType = typeof data;
139
+ if (!this.headers.has("Content-Type")) {
140
+ this.headers.set("Content-Type", (_a = typeMap[dataType]) !== null && _a !== void 0 ? _a : "text/plain; charset=utf-8");
141
+ }
142
+ const responseData = dataType === "object" && data !== null ? JSON.stringify(data) : data;
143
+ return new Response(responseData, { status, headers: this.headers });
144
+ }
145
+ json(object, status = 200) {
146
+ // this.status = status;
147
+ // if (!this.headers.has("Content-Type")) {
148
+ // this.headers.set("Content-Type", "application/json; charset=utf-8");
149
+ // }
150
+ return Response.json(object, { status, headers: this.headers });
151
+ }
152
+ file(filePath, mime_Type, status = 200) {
153
+ // this.status = status;
154
+ const file = Bun.file(filePath);
155
+ if (!this.headers.has("Content-Type")) {
156
+ this.headers.set("Content-Type", mime_Type !== null && mime_Type !== void 0 ? mime_Type : getMimeType(filePath));
157
+ }
158
+ return new Response(file, { status, headers: this.headers });
159
+ }
160
+ ejs(viewPath_1) {
161
+ return __awaiter(this, arguments, void 0, function* (viewPath, data = {}, status = 200) {
162
+ // this.status = status;
163
+ const ejs = yield getEjs();
164
+ try {
165
+ const template = yield Bun.file(viewPath).text();
166
+ const rendered = ejs.render(template, data);
167
+ const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" });
168
+ return new Response(rendered, { status, headers });
169
+ }
170
+ catch (error) {
171
+ console.error("EJS Rendering Error:", error);
172
+ return new Response("Error rendering template", { status: 500 });
173
+ }
174
+ });
175
+ }
176
+ redirect(path, status = 302) {
177
+ // this.status = status
178
+ this.headers.set("Location", path);
179
+ return new Response(null, { status, headers: this.headers });
180
+ }
181
+ setCookie(name, value, options = {}) {
182
+ let cookieString = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
183
+ if (options.maxAge)
184
+ cookieString += `; Max-Age=${options.maxAge}`;
185
+ if (options.expires)
186
+ cookieString += `; Expires=${options.expires.toUTCString()}`;
187
+ if (options.path)
188
+ cookieString += `; Path=${options.path}`;
189
+ if (options.domain)
190
+ cookieString += `; Domain=${options.domain}`;
191
+ if (options.secure)
192
+ cookieString += `; Secure`;
193
+ if (options.httpOnly)
194
+ cookieString += `; HttpOnly`;
195
+ if (options.sameSite)
196
+ cookieString += `; SameSite=${options.sameSite}`;
197
+ this.headers.append("Set-Cookie", cookieString);
198
+ return this;
199
+ }
200
+ get cookies() {
201
+ if (!this.parsedCookies) {
202
+ const cookieHeader = this.req.headers.get("cookie");
203
+ this.parsedCookies = cookieHeader ? parseCookie(cookieHeader) : {};
204
+ }
205
+ return this.parsedCookies;
206
+ }
207
+ // Streams
208
+ stream(callback) {
209
+ const headers = new Headers(this.headers);
210
+ const stream = new ReadableStream({
211
+ start(controller) {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ yield callback(controller);
214
+ controller.close();
215
+ });
216
+ },
217
+ });
218
+ return new Response(stream, { headers });
219
+ }
220
+ yieldStream(callback) {
221
+ return new Response(
222
+ // {
223
+ // async *[Symbol.asyncIterator]() {
224
+ // yield* callback();
225
+ // },
226
+ // },
227
+ // { headers: this.headers }
228
+ );
229
+ }
230
+ }
231
+ // function parseCookie(cookieHeader: string | undefined): Record<string, string> {
232
+ // const cookies: Record<string, string> = {};
233
+ // const cookiesArray = cookieHeader?.split(";")!;
234
+ // for (let i = 0; i < cookiesArray?.length!; i++) {
235
+ // const [cookieName, ...cookieValeParts] = cookiesArray[i].trim().split("=");
236
+ // const cookieVale = cookieValeParts?.join("=").trim();
237
+ // if (cookieName) {
238
+ // cookies[cookieName.trim()] = decodeURIComponent(cookieVale);
239
+ // }
240
+ // }
241
+ // return cookies;
242
+ // }
243
+ function parseCookie(cookieHeader) {
244
+ return Object.fromEntries(cookieHeader.split(";").map((cookie) => {
245
+ const [name, ...valueParts] = cookie.trim().split("=");
246
+ return [name, decodeURIComponent(valueParts.join("="))];
247
+ }));
248
+ }
249
+ export function extractParam(paramNames, incomingPath) {
250
+ // ["id","name"]
251
+ const param = {};
252
+ // inComingpath = /user/2/pradeep
253
+ const [pathWithoutQuery] = incomingPath.split("?");
254
+ const pathSegments = pathWithoutQuery.split("/").filter(s => s !== '');
255
+ // let segmentStart = 0
256
+ // let segmentIndex = 0
257
+ // const segments: string[] = []
258
+ // for (let i = 0; i <= pathWithoutQuery.length; i++) {
259
+ // if (i === pathWithoutQuery.length || pathWithoutQuery.charCodeAt(i) === 47) { // '/'
260
+ // if (i > segmentStart) {
261
+ // segments[segmentIndex++] = pathWithoutQuery.slice(segmentStart, i)
262
+ // }
263
+ // segmentStart = i + 1
264
+ // }
265
+ // }
266
+ const start = pathSegments.length - paramNames.length;
267
+ for (let i = 0; i < paramNames.length; i++) {
268
+ param[paramNames[i]] = pathSegments[start + i];
269
+ }
270
+ return param;
271
+ }
272
+ export function extractDynamicParams(originalPath, incomingPath) {
273
+ const params = {};
274
+ const routeSegments = originalPath.split("/");
275
+ const [pathWithoutQuery] = incomingPath.split("?");
276
+ const pathSegments = pathWithoutQuery.split("/");
277
+ if (routeSegments.length !== pathSegments.length)
278
+ return null;
279
+ for (let i = 0; i < routeSegments.length; i++) {
280
+ const segment = routeSegments[i];
281
+ if (segment.charCodeAt(0) === 58) {
282
+ params[segment.slice(1)] = pathSegments[i];
283
+ }
284
+ }
285
+ return params;
286
+ }
287
+ function parseBody(req) {
288
+ return __awaiter(this, void 0, void 0, function* () {
289
+ const contentType = req.headers.get("Content-Type") || '';
290
+ if (!contentType)
291
+ return {};
292
+ const contentLength = req.headers.get("Content-Length");
293
+ if (contentLength === "0" || !req.body) {
294
+ return {};
295
+ }
296
+ if (contentType.startsWith("application/json")) {
297
+ return yield req.json();
298
+ }
299
+ if (contentType.startsWith("application/x-www-form-urlencoded")) {
300
+ const body = yield req.text();
301
+ return Object.fromEntries(new URLSearchParams(body));
302
+ }
303
+ if (contentType.startsWith("multipart/form-data")) {
304
+ const formData = yield req.formData();
305
+ const obj = {};
306
+ for (const [key, value] of formData.entries()) {
307
+ obj[key] = value;
308
+ }
309
+ return obj;
310
+ }
311
+ return { error: "Unknown request body type" };
312
+ });
313
+ }
314
+ // Deprecated
315
+ // export default function createCtx(
316
+ // req: Request,
317
+ // server: Server,
318
+ // pathname: string,
319
+ // // onn: (event: string | symbol, listener: EventListener) => void,
320
+ // // emitter: (event: string | symbol, ...args: any) => void,
321
+ // routePattern: string | undefined
322
+ // ): ContextType {
323
+ // let parsedQuery: Record<string, string> | null = null;
324
+ // let parsedParams: Record<string, string> | null = null;
325
+ // let parsedCookies: Record<string, string> | null = null;
326
+ // let parsedBody: Promise<any> | null = null;
327
+ // let contextData: Record<string, any> = {};
328
+ // let urlObject: URL | null = null
329
+ // return {
330
+ // req,
331
+ // server,
332
+ // pathname,
333
+ // // status: 200,
334
+ // headers: new Headers(),
335
+ // // on(event: string | symbol, listener: EventListener) {
336
+ // // onn(event, listener)
337
+ // // },
338
+ // // emit(event: string | symbol, ...args: any) {
339
+ // // emitter(event, ...args)
340
+ // // },
341
+ // setHeader(key: string, value: string): ContextType {
342
+ // this.headers.set(key, value);
343
+ // return this;
344
+ // },
345
+ // removeHeader(key: string): ContextType {
346
+ // this.headers.delete(key)
347
+ // return this
348
+ // },
349
+ // set<T>(key: string, value: T): ContextType {
350
+ // contextData[key] = value;
351
+ // return this;
352
+ // },
353
+ // get<T>(key: string): T | undefined {
354
+ // return contextData[key];
355
+ // },
356
+ // get ip(): string | null {
357
+ // return this.server.requestIP(req)?.address ?? null;
358
+ // },
359
+ // get url(): URL {
360
+ // if (!urlObject) {
361
+ // urlObject = new URL(req.url)
362
+ // }
363
+ // return urlObject
364
+ // },
365
+ // get query(): Record<string, string> {
366
+ // if (!parsedQuery) {
367
+ // if (!this.url.search) return {};
368
+ // parsedQuery = Object.fromEntries(this.url.searchParams);
369
+ // }
370
+ // return parsedQuery;
371
+ // },
372
+ // get params(): Record<string, string> {
373
+ // if (!parsedParams && routePattern) {
374
+ // try {
375
+ // parsedParams = extractDynamicParams(routePattern, pathname);
376
+ // } catch (error) {
377
+ // const message = error instanceof Error ? error.message : String(error)
378
+ // throw new Error(`Failed to extract route parameters: ${message}`);
379
+ // }
380
+ // }
381
+ // return parsedParams ?? {};
382
+ // },
383
+ // get body(): Promise<any> {
384
+ // if (req.method === "GET") {
385
+ // return Promise.resolve({});
386
+ // }
387
+ // if (!parsedBody) {
388
+ // parsedBody = (async () => {
389
+ // try {
390
+ // const result = await parseBody(req);
391
+ // if (result.error) {
392
+ // throw new Error(result.error);
393
+ // }
394
+ // return Object.keys(result).length === 0 ? null : result;
395
+ // } catch (error) {
396
+ // throw new Error("Invalid request body format");
397
+ // // const message = error instanceof Error ? error.message : String(error);
398
+ // // throw new Error(`Failed to parse request body: ${message}`);
399
+ // }
400
+ // })();
401
+ // }
402
+ // return parsedBody;
403
+ // },
404
+ // text(data: string, status: number = 200) {
405
+ // return new Response(data, {
406
+ // status,
407
+ // headers: this.headers
408
+ // });
409
+ // },
410
+ // send<T>(data: T, status: number = 200): Response {
411
+ // // this.status = status;
412
+ // // const dataType = data instanceof Uint8Array ? "Uint8Array"
413
+ // // : data instanceof ArrayBuffer ? "ArrayBuffer"
414
+ // // : typeof data;
415
+ // let dataType: string
416
+ // if (data instanceof Uint8Array) dataType = "Uint8Array"
417
+ // else if (data instanceof ArrayBuffer) dataType = 'ArrayBuffer'
418
+ // else dataType = typeof data
419
+ // // if (!this.headers.has("Content-Type")) {
420
+ // // this.headers.set("Content-Type", typeMap[dataType] ?? "text/plain; charset=utf-8");
421
+ // // }
422
+ // const responseData =
423
+ // dataType === "object" && data !== null ? JSON.stringify(data) : (data as any);
424
+ // return new Response(responseData, { status, headers: this.headers });
425
+ // },
426
+ // json<T>(object: T, status: number = 200): Response {
427
+ // // this.status = status;
428
+ // // if (!this.headers.has("Content-Type")) {
429
+ // // this.headers.set("Content-Type", "application/json; charset=utf-8");
430
+ // // }
431
+ // return Response.json(object, { status, headers: this.headers })
432
+ // },
433
+ // file(filePath: string, mime_Type?: string, status: number = 200): Response {
434
+ // // this.status = status;
435
+ // const file = Bun.file(filePath);
436
+ // if (!this.headers.has("Content-Type")) {
437
+ // this.headers.set("Content-Type", mime_Type ?? getMimeType(filePath));
438
+ // }
439
+ // return new Response(file, { status, headers: this.headers });
440
+ // },
441
+ // async ejs(viewPath: string, data = {}, status: number = 200): Promise<Response> {
442
+ // // this.status = status;
443
+ // const ejs = await getEjs();
444
+ // try {
445
+ // const template = await Bun.file(viewPath).text()
446
+ // const rendered = ejs.render(template, data)
447
+ // const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" });
448
+ // return new Response(rendered, { status, headers });
449
+ // } catch (error) {
450
+ // console.error("EJS Rendering Error:", error);
451
+ // return new Response("Error rendering template", { status: 500 });
452
+ // }
453
+ // },
454
+ // redirect(path: string, status: number = 302): Response {
455
+ // // this.status = status
456
+ // this.headers.set("Location", path);
457
+ // return new Response(null, { status, headers: this.headers });
458
+ // },
459
+ // stream(callback: (controller: ReadableStreamDefaultController) => void) {
460
+ // const headers = new Headers(this.headers)
461
+ // const stream = new ReadableStream({
462
+ // async start(controller) {
463
+ // await callback(controller);
464
+ // controller.close();
465
+ // },
466
+ // });
467
+ // return new Response(stream, {
468
+ // headers
469
+ // });
470
+ // },
471
+ // yieldStream(callback: () => AsyncIterable<any>): Response {
472
+ // return new Response("not working stream yet.")
473
+ // // return new Response(
474
+ // // {
475
+ // // async *[Symbol.asyncIterator ]() {
476
+ // // yield* callback();
477
+ // // },
478
+ // // },
479
+ // // { headers: this.headers }
480
+ // // );
481
+ // },
482
+ // setCookie(
483
+ // name: string,
484
+ // value: string,
485
+ // options: CookieOptions = {}
486
+ // ): ContextType {
487
+ // let cookieString = `${encodeURIComponent(name)}=${encodeURIComponent(
488
+ // value
489
+ // )}`;
490
+ // if (options.maxAge) cookieString += `; Max-Age=${options.maxAge}`;
491
+ // if (options.expires)
492
+ // cookieString += `; Expires=${options.expires.toUTCString()}`;
493
+ // if (options.path) cookieString += `; Path=${options.path}`;
494
+ // if (options.domain) cookieString += `; Domain=${options.domain}`;
495
+ // if (options.secure) cookieString += `; Secure`;
496
+ // if (options.httpOnly) cookieString += `; HttpOnly`;
497
+ // if (options.sameSite) cookieString += `; SameSite=${options.sameSite}`;
498
+ // this.headers.append("Set-Cookie", cookieString);
499
+ // return this;
500
+ // },
501
+ // get cookies(): Record<string, string> {
502
+ // if (!parsedCookies) {
503
+ // const cookieHeader = this.req.headers.get("cookie");
504
+ // parsedCookies = cookieHeader ? parseCookie(cookieHeader) : {};
505
+ // }
506
+ // return parsedCookies;
507
+ // },
508
+ // };
509
+ // }