diesel-core 1.5.9 → 1.6.1
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/adaptor/node/conninfo.d.ts +9 -0
- package/dist/adaptor/node/conninfo.js +37 -0
- package/dist/adaptor/node/main.d.ts +5 -0
- package/dist/adaptor/node/main.js +110 -0
- package/dist/ctx.d.ts +3 -1
- package/dist/ctx.js +9 -9
- package/dist/handleRequest.js +16 -16
- package/dist/main.d.ts +13 -37
- package/dist/main.js +90 -90
- package/dist/middlewares/logger/logger.js +1 -1
- package/dist/request_pipeline.js +68 -68
- package/dist/router/find-my-way.d.ts +2 -1
- package/dist/router/find-my-way.js +27 -27
- package/dist/router/interface.d.ts +3 -2
- package/dist/router/interface.js +61 -61
- package/dist/router/trie.d.ts +8 -5
- package/dist/router/trie.js +1 -1
- package/dist/router/trie2.d.ts +34 -0
- package/dist/router/trie2.test.d.ts +0 -0
- package/dist/types.d.ts +15 -0
- package/package.json +2 -1
- package/dist/trie.d.ts +0 -23
- package/dist/trie.js +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.connInfo = connInfo;
|
|
4
|
+
function connInfo(req) {
|
|
5
|
+
var _a, _b, _c, _d;
|
|
6
|
+
var headers = {};
|
|
7
|
+
console.log(req.socket);
|
|
8
|
+
if ('headers' in req) {
|
|
9
|
+
if ('get' in req.headers) {
|
|
10
|
+
headers = Object.fromEntries((_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a.entries());
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
headers = req.headers;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var protocol = ((_b = headers['x-forwarded-proto']) === null || _b === void 0 ? void 0 : _b.split(',')[0]) ||
|
|
17
|
+
('socket' in req && ((_c = req.socket) === null || _c === void 0 ? void 0 : _c.encrypted) ? 'https' : 'http');
|
|
18
|
+
var host = headers['host'] || '';
|
|
19
|
+
var ip;
|
|
20
|
+
var forwarded = headers['x-forwarded-for'];
|
|
21
|
+
if (forwarded) {
|
|
22
|
+
ip = forwarded.split(',')[0].trim();
|
|
23
|
+
}
|
|
24
|
+
else if ('socket' in req && ((_d = req.socket) === null || _d === void 0 ? void 0 : _d.remoteAddress)) {
|
|
25
|
+
ip = req.socket.remoteAddress;
|
|
26
|
+
}
|
|
27
|
+
var url = 'url' in req
|
|
28
|
+
? req.url
|
|
29
|
+
: "".concat(protocol, "://").concat(host).concat(req.url || '');
|
|
30
|
+
return {
|
|
31
|
+
protocol: protocol,
|
|
32
|
+
host: host,
|
|
33
|
+
url: url,
|
|
34
|
+
ip: ip,
|
|
35
|
+
headers: headers,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.serve = serve;
|
|
40
|
+
var http = require("node:http");
|
|
41
|
+
function convertNodeReqToWebReq(req) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var protocol, url, init;
|
|
44
|
+
var _a;
|
|
45
|
+
return __generator(this, function (_b) {
|
|
46
|
+
protocol = ((_a = req.headers['x-forwarded-proto']) === null || _a === void 0 ? void 0 : _a.split(',')[0]) || 'http';
|
|
47
|
+
url = "".concat(protocol, "://").concat(req.headers.host).concat(req.url);
|
|
48
|
+
init = {
|
|
49
|
+
method: req.method,
|
|
50
|
+
headers: req.headers,
|
|
51
|
+
body: null
|
|
52
|
+
};
|
|
53
|
+
if (req.method !== 'GET' && req.method !== 'PUT') {
|
|
54
|
+
init.body = new ReadableStream({
|
|
55
|
+
start: function (controller) {
|
|
56
|
+
req.on('data', function (chunk) { return controller.enqueue(new Uint8Array(chunk)); });
|
|
57
|
+
req.on('end', function () { return controller.close(); });
|
|
58
|
+
req.on('error', function (err) { return controller.error(err); });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return [2 /*return*/, new Request(url, init)];
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function sendWebResToNodeRes(webRes, nodeRes) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var reader, result;
|
|
69
|
+
var _a;
|
|
70
|
+
return __generator(this, function (_b) {
|
|
71
|
+
switch (_b.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
nodeRes.writeHead(webRes.status, Object.fromEntries(webRes.headers));
|
|
74
|
+
reader = (_a = webRes.body) === null || _a === void 0 ? void 0 : _a.getReader();
|
|
75
|
+
if (!reader) return [3 /*break*/, 3];
|
|
76
|
+
result = void 0;
|
|
77
|
+
_b.label = 1;
|
|
78
|
+
case 1: return [4 /*yield*/, reader.read()];
|
|
79
|
+
case 2:
|
|
80
|
+
if (!!(result = _b.sent()).done) return [3 /*break*/, 3];
|
|
81
|
+
nodeRes.write(Buffer.from(result.value));
|
|
82
|
+
return [3 /*break*/, 1];
|
|
83
|
+
case 3:
|
|
84
|
+
nodeRes.end();
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function serve(options) {
|
|
91
|
+
var _this = this;
|
|
92
|
+
var server = http.createServer(function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
93
|
+
var webRequest, webRes;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0: return [4 /*yield*/, convertNodeReqToWebReq(request)];
|
|
97
|
+
case 1:
|
|
98
|
+
webRequest = _a.sent();
|
|
99
|
+
return [4 /*yield*/, options.fetch(webRequest, server)];
|
|
100
|
+
case 2:
|
|
101
|
+
webRes = _a.sent();
|
|
102
|
+
return [4 /*yield*/, sendWebResToNodeRes(webRes, response)];
|
|
103
|
+
case 3:
|
|
104
|
+
_a.sent();
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}); });
|
|
109
|
+
server.listen(options.port, function () { return console.log('node server running on port 3000'); });
|
|
110
|
+
}
|
package/dist/ctx.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class Context implements ContextType {
|
|
|
5
5
|
server?: Server | undefined;
|
|
6
6
|
path?: string | undefined;
|
|
7
7
|
routePattern?: string;
|
|
8
|
+
paramNames?: string[] | Record<string, string>;
|
|
8
9
|
env?: Record<string, any>;
|
|
9
10
|
executionContext?: any | undefined;
|
|
10
11
|
headers: Headers;
|
|
@@ -14,7 +15,7 @@ export declare class Context implements ContextType {
|
|
|
14
15
|
private parsedBody;
|
|
15
16
|
private contextData;
|
|
16
17
|
private urlObject;
|
|
17
|
-
constructor(req: Request, server?: Server, path?: string, routePattern?: string, env?: Record<string, any>, executionContext?: any);
|
|
18
|
+
constructor(req: Request, server?: Server, path?: string, routePattern?: string, paramNames?: string[] | Record<string, string>, env?: Record<string, any>, executionContext?: any);
|
|
18
19
|
setHeader(key: string, value: string): this;
|
|
19
20
|
removeHeader(key: string): this;
|
|
20
21
|
set<T>(key: string, value: T): this;
|
|
@@ -35,4 +36,5 @@ export declare class Context implements ContextType {
|
|
|
35
36
|
stream(callback: (controller: ReadableStreamDefaultController) => void): Response;
|
|
36
37
|
yieldStream(callback: () => AsyncIterable<any>): Response;
|
|
37
38
|
}
|
|
39
|
+
export declare function extractParam(paramNames: string[], incomingPath: string): Record<string, string>;
|
|
38
40
|
export declare function extractDynamicParams(originalPath: string, incomingPath: string): Record<string, string> | null;
|
package/dist/ctx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var U1=Object.create;var{getPrototypeOf:W1,defineProperty:X,getOwnPropertyNames:u,getOwnPropertyDescriptor:M1}=Object,
|
|
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={"&":"&","<":"<",">":">",'"':""","'":"'"},k1=/[&<>'"]/g;function I1(f){return x1[f]||f}var E1=`var _ENCODE_HTML_RULES = {
|
|
2
2
|
"&": "&"
|
|
3
3
|
, "<": "<"
|
|
4
4
|
, ">": ">"
|
|
@@ -9,17 +9,17 @@ var U1=Object.create;var{getPrototypeOf:W1,defineProperty:X,getOwnPropertyNames:
|
|
|
9
9
|
function encode_char(c) {
|
|
10
10
|
return _ENCODE_HTML_RULES[c] || c;
|
|
11
11
|
};
|
|
12
|
-
`;
|
|
13
|
-
`+
|
|
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,
|
|
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
15
|
`);throw f.path=K,f.message=(K||"ejs")+":"+A+`
|
|
16
16
|
`+Y+`
|
|
17
17
|
|
|
18
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
19
|
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
|
-
`,g.outputFunctionName){if(!
|
|
21
|
-
`}if(g.localsName&&!
|
|
22
|
-
`;for(var Y=0;Y<g.destructuredLocals.length;Y++){var z=g.destructuredLocals[Y];if(!
|
|
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
23
|
`;K+=z+" = __locals."+z}A+=K+`;
|
|
24
24
|
`}if(g._with!==!1)A+=" with ("+g.localsName+` || {}) {
|
|
25
25
|
`,C+=` }
|
|
@@ -40,7 +40,7 @@ try {
|
|
|
40
40
|
|
|
41
41
|
`,J.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
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
|
|
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
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
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
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)+`")
|
|
@@ -51,4 +51,4 @@ try {
|
|
|
51
51
|
`;break;case $.modes.ESCAPED:this.source+=" ; __append(escapeFn("+K1(f)+`))
|
|
52
52
|
`;break;case $.modes.RAW:this.source+=" ; __append("+K1(f)+`)
|
|
53
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}
|
|
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(!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};
|
package/dist/handleRequest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Of=Object.create;var{getPrototypeOf:Lf,defineProperty:M,getOwnPropertyNames:i,getOwnPropertyDescriptor:Sf}=Object,u=Object.prototype.hasOwnProperty;var bf=(f,w,g)=>{g=f!=null?Of(Lf(f)):{};let A=w||!f||!f.__esModule?M(g,"default",{value:f,enumerable:!0}):g;for(let $ of i(f))if(!u.call(A,$))M(A,$,{get:()=>f[$],enumerable:!0});return A},r=new WeakMap,Ef=(f)=>{var w=r.get(f),g;if(w)return w;if(w=M({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")i(f).map((A)=>!u.call(w,A)&&M(w,A,{get:()=>f[A],enumerable:!(g=Sf(f,A))||g.enumerable}));return r.set(f,w),w},L=(f,w)=>()=>(w||f((w={exports:{}}).exports,w),w.exports);var qf=(f,w)=>{for(var g in w)M(f,g,{get:w[g],enumerable:!0,configurable:!0,set:(A)=>w[g]=()=>A})};var Tf=(f,w)=>()=>(f&&(w=f(f=0)),w);var cf=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(w,g)=>(typeof require!=="undefined"?require:w)[g]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var wf={};qf(wf,{sep:()=>e,resolve:()=>K,relative:()=>d,posix:()=>gf,parse:()=>t,normalize:()=>S,join:()=>
|
|
1
|
+
var Of=Object.create;var{getPrototypeOf:Lf,defineProperty:M,getOwnPropertyNames:i,getOwnPropertyDescriptor:Sf}=Object,u=Object.prototype.hasOwnProperty;var bf=(f,w,g)=>{g=f!=null?Of(Lf(f)):{};let A=w||!f||!f.__esModule?M(g,"default",{value:f,enumerable:!0}):g;for(let $ of i(f))if(!u.call(A,$))M(A,$,{get:()=>f[$],enumerable:!0});return A},r=new WeakMap,Ef=(f)=>{var w=r.get(f),g;if(w)return w;if(w=M({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")i(f).map((A)=>!u.call(w,A)&&M(w,A,{get:()=>f[A],enumerable:!(g=Sf(f,A))||g.enumerable}));return r.set(f,w),w},L=(f,w)=>()=>(w||f((w={exports:{}}).exports,w),w.exports);var qf=(f,w)=>{for(var g in w)M(f,g,{get:w[g],enumerable:!0,configurable:!0,set:(A)=>w[g]=()=>A})};var Tf=(f,w)=>()=>(f&&(w=f(f=0)),w);var cf=((f)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(f,{get:(w,g)=>(typeof require!=="undefined"?require:w)[g]}):f)(function(f){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+f+'" is not supported')});var wf={};qf(wf,{sep:()=>e,resolve:()=>K,relative:()=>d,posix:()=>gf,parse:()=>t,normalize:()=>S,join:()=>m,isAbsolute:()=>h,format:()=>p,extname:()=>a,dirname:()=>o,delimiter:()=>ff,default:()=>_f,basename:()=>s,_makeLong:()=>l});function W(f){if(typeof f!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function n(f,w){var g="",A=0,$=-1,z=0,J;for(var Y=0;Y<=f.length;++Y){if(Y<f.length)J=f.charCodeAt(Y);else if(J===47)break;else J=47;if(J===47){if($===Y-1||z===1);else if($!==Y-1&&z===2){if(g.length<2||A!==2||g.charCodeAt(g.length-1)!==46||g.charCodeAt(g.length-2)!==46){if(g.length>2){var j=g.lastIndexOf("/");if(j!==g.length-1){if(j===-1)g="",A=0;else g=g.slice(0,j),A=g.length-1-g.lastIndexOf("/");$=Y,z=0;continue}}else if(g.length===2||g.length===1){g="",A=0,$=Y,z=0;continue}}if(w){if(g.length>0)g+="/..";else g="..";A=2}}else{if(g.length>0)g+="/"+f.slice($+1,Y);else g=f.slice($+1,Y);A=Y-$-1}$=Y,z=0}else if(J===46&&z!==-1)++z;else z=-1}return g}function Pf(f,w){var g=w.dir||w.root,A=w.base||(w.name||"")+(w.ext||"");if(!g)return A;if(g===w.root)return g+A;return g+f+A}function K(){var f="",w=!1,g;for(var A=arguments.length-1;A>=-1&&!w;A--){var $;if(A>=0)$=arguments[A];else{if(g===void 0)g=process.cwd();$=g}if(W($),$.length===0)continue;f=$+"/"+f,w=$.charCodeAt(0)===47}if(f=n(f,!w),w)if(f.length>0)return"/"+f;else return"/";else if(f.length>0)return f;else return"."}function S(f){if(W(f),f.length===0)return".";var w=f.charCodeAt(0)===47,g=f.charCodeAt(f.length-1)===47;if(f=n(f,!w),f.length===0&&!w)f=".";if(f.length>0&&g)f+="/";if(w)return"/"+f;return f}function h(f){return W(f),f.length>0&&f.charCodeAt(0)===47}function m(){if(arguments.length===0)return".";var f;for(var w=0;w<arguments.length;++w){var g=arguments[w];if(W(g),g.length>0)if(f===void 0)f=g;else f+="/"+g}if(f===void 0)return".";return S(f)}function d(f,w){if(W(f),W(w),f===w)return"";if(f=K(f),w=K(w),f===w)return"";var g=1;for(;g<f.length;++g)if(f.charCodeAt(g)!==47)break;var A=f.length,$=A-g,z=1;for(;z<w.length;++z)if(w.charCodeAt(z)!==47)break;var J=w.length,Y=J-z,j=$<Y?$:Y,V=-1,Z=0;for(;Z<=j;++Z){if(Z===j){if(Y>j){if(w.charCodeAt(z+Z)===47)return w.slice(z+Z+1);else if(Z===0)return w.slice(z+Z)}else if($>j){if(f.charCodeAt(g+Z)===47)V=Z;else if(Z===0)V=0}break}var F=f.charCodeAt(g+Z),B=w.charCodeAt(z+Z);if(F!==B)break;else if(F===47)V=Z}var G="";for(Z=g+V+1;Z<=A;++Z)if(Z===A||f.charCodeAt(Z)===47)if(G.length===0)G+="..";else G+="/..";if(G.length>0)return G+w.slice(z+V);else{if(z+=V,w.charCodeAt(z)===47)++z;return w.slice(z)}}function l(f){return f}function o(f){if(W(f),f.length===0)return".";var w=f.charCodeAt(0),g=w===47,A=-1,$=!0;for(var z=f.length-1;z>=1;--z)if(w=f.charCodeAt(z),w===47){if(!$){A=z;break}}else $=!1;if(A===-1)return g?"/":".";if(g&&A===1)return"//";return f.slice(0,A)}function s(f,w){if(w!==void 0&&typeof w!=="string")throw new TypeError('"ext" argument must be a string');W(f);var g=0,A=-1,$=!0,z;if(w!==void 0&&w.length>0&&w.length<=f.length){if(w.length===f.length&&w===f)return"";var J=w.length-1,Y=-1;for(z=f.length-1;z>=0;--z){var j=f.charCodeAt(z);if(j===47){if(!$){g=z+1;break}}else{if(Y===-1)$=!1,Y=z+1;if(J>=0)if(j===w.charCodeAt(J)){if(--J===-1)A=z}else J=-1,A=Y}}if(g===A)A=Y;else if(A===-1)A=f.length;return f.slice(g,A)}else{for(z=f.length-1;z>=0;--z)if(f.charCodeAt(z)===47){if(!$){g=z+1;break}}else if(A===-1)$=!1,A=z+1;if(A===-1)return"";return f.slice(g,A)}}function a(f){W(f);var w=-1,g=0,A=-1,$=!0,z=0;for(var J=f.length-1;J>=0;--J){var Y=f.charCodeAt(J);if(Y===47){if(!$){g=J+1;break}continue}if(A===-1)$=!1,A=J+1;if(Y===46){if(w===-1)w=J;else if(z!==1)z=1}else if(w!==-1)z=-1}if(w===-1||A===-1||z===0||z===1&&w===A-1&&w===g+1)return"";return f.slice(w,A)}function p(f){if(f===null||typeof f!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof f);return Pf("/",f)}function t(f){W(f);var w={root:"",dir:"",base:"",ext:"",name:""};if(f.length===0)return w;var g=f.charCodeAt(0),A=g===47,$;if(A)w.root="/",$=1;else $=0;var z=-1,J=0,Y=-1,j=!0,V=f.length-1,Z=0;for(;V>=$;--V){if(g=f.charCodeAt(V),g===47){if(!j){J=V+1;break}continue}if(Y===-1)j=!1,Y=V+1;if(g===46){if(z===-1)z=V;else if(Z!==1)Z=1}else if(z!==-1)Z=-1}if(z===-1||Y===-1||Z===0||Z===1&&z===Y-1&&z===J+1){if(Y!==-1)if(J===0&&A)w.base=w.name=f.slice(1,Y);else w.base=w.name=f.slice(J,Y)}else{if(J===0&&A)w.name=f.slice(1,z),w.base=f.slice(1,Y);else w.name=f.slice(J,z),w.base=f.slice(J,Y);w.ext=f.slice(z,Y)}if(J>0)w.dir=f.slice(0,J-1);else if(A)w.dir="/";return w}var e="/",ff=":",gf,_f;var Af=Tf(()=>{gf=((f)=>(f.posix=f,f))({resolve:K,normalize:S,isAbsolute:h,join:m,relative:d,_makeLong:l,dirname:o,basename:s,extname:a,format:p,parse:t,sep:e,delimiter:ff,win32:null,posix:null}),_f=gf});var Jf=L((nf)=>{var yf=/[|\\{}()[\]^$+*?.]/g,kf=Object.prototype.hasOwnProperty,E=function(f,w){return kf.apply(f,[w])};nf.escapeRegExpChars=function(f){if(!f)return"";return String(f).replace(yf,"\\$&")};var If={"&":"&","<":"<",">":">",'"':""","'":"'"},xf=/[&<>'"]/g;function rf(f){return If[f]||f}var uf=`var _ENCODE_HTML_RULES = {
|
|
2
2
|
"&": "&"
|
|
3
3
|
, "<": "<"
|
|
4
4
|
, ">": ">"
|
|
@@ -10,12 +10,12 @@ function encode_char(c) {
|
|
|
10
10
|
return _ENCODE_HTML_RULES[c] || c;
|
|
11
11
|
};
|
|
12
12
|
`;nf.escapeXML=function(f){return f==null?"":String(f).replace(xf,rf)};function $f(){return Function.prototype.toString.call(this)+`;
|
|
13
|
-
`+uf}try{if(typeof Object.defineProperty==="function")Object.defineProperty(nf.escapeXML,"toString",{value:$f});else nf.escapeXML.toString=$f}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}nf.shallowCopy=function(f,w){if(w=w||{},f!==null&&f!==void 0)for(var g in w){if(!E(w,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=w[g]}return f};nf.shallowCopyFromList=function(f,w,g){if(g=g||[],w=w||{},f!==null&&f!==void 0)for(var A=0;A<g.length;A++){var $=g[A];if(typeof w[$]!="undefined"){if(!E(w,$))continue;if($==="__proto__"||$==="constructor")continue;f[$]=w[$]}}return f};nf.cache={_data:{},set:function(f,w){this._data[f]=w},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};nf.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(w){return w[1].toUpperCase()})};nf.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{}}}();nf.hasOwnOnlyObject=function(f){var w=nf.createNullProtoObjWherePossible();for(var g in f)if(E(f,g))w[g]=f[g];return w}});var Yf=L((
|
|
14
|
-
`),J=Math.max(A-3,0),Y=Math.min(z.length,A+3),j=$(g),V=z.slice(J,Y).map(function(Z,
|
|
13
|
+
`+uf}try{if(typeof Object.defineProperty==="function")Object.defineProperty(nf.escapeXML,"toString",{value:$f});else nf.escapeXML.toString=$f}catch(f){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}nf.shallowCopy=function(f,w){if(w=w||{},f!==null&&f!==void 0)for(var g in w){if(!E(w,g))continue;if(g==="__proto__"||g==="constructor")continue;f[g]=w[g]}return f};nf.shallowCopyFromList=function(f,w,g){if(g=g||[],w=w||{},f!==null&&f!==void 0)for(var A=0;A<g.length;A++){var $=g[A];if(typeof w[$]!="undefined"){if(!E(w,$))continue;if($==="__proto__"||$==="constructor")continue;f[$]=w[$]}}return f};nf.cache={_data:{},set:function(f,w){this._data[f]=w},get:function(f){return this._data[f]},remove:function(f){delete this._data[f]},reset:function(){this._data={}}};nf.hyphenToCamel=function(f){return f.replace(/-[a-z]/g,function(w){return w[1].toUpperCase()})};nf.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{}}}();nf.hasOwnOnlyObject=function(f){var w=nf.createNullProtoObjWherePossible();for(var g in f)if(E(f,g))w[g]=f[g];return w}});var Yf=L((L1,af)=>{af.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 Uf=L((Gf)=>{var c=(()=>({})),R=(Af(),Ef(wf)),Q=Jf(),Zf=!1,pf=Yf().version,tf="<",ef=">",f1="%",Cf="locals",g1="ejs",w1="(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)",Ff=["delimiter","scope","context","debug","compileDebug","client","_with","rmWhitespace","strict","filename","async"],A1=Ff.concat("cache"),jf=/^\uFEFF/,q=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/;Gf.cache=Q.cache;Gf.fileLoader=c.readFileSync;Gf.localsName=Cf;Gf.promiseImpl=new Function("return this;")().Promise;Gf.resolveInclude=function(f,w,g){var{dirname:A,extname:$,resolve:z}=R,J=z(g?w:A(w),f),Y=$(f);if(!Y)J+=".ejs";return J};function Vf(f,w){var g;if(w.some(function(A){return g=Gf.resolveInclude(f,A,!0),c.existsSync(g)}))return g}function $1(f,w){var g,A,$=w.views,z=/^[A-Za-z]+:\\|^\//.exec(f);if(z&&z.length)if(f=f.replace(/^\/*/,""),Array.isArray(w.root))g=Vf(f,w.root);else g=Gf.resolveInclude(f,w.root||"/",!0);else{if(w.filename){if(A=Gf.resolveInclude(f,w.filename),c.existsSync(A))g=A}if(!g&&Array.isArray($))g=Vf(f,$);if(!g&&typeof w.includer!=="function")throw new Error('Could not find the include file "'+w.escapeFunction(f)+'"')}return g}function U(f,w){var g,A=f.filename,$=arguments.length>1;if(f.cache){if(!A)throw new Error("cache option requires a filename");if(g=Gf.cache.get(A),g)return g;if(!$)w=Bf(A).toString().replace(jf,"")}else if(!$){if(!A)throw new Error("Internal EJS error: no file name or template provided");w=Bf(A).toString().replace(jf,"")}if(g=Gf.compile(w,f),f.cache)Gf.cache.set(A,g);return g}function z1(f,w,g){var A;if(!g)if(typeof Gf.promiseImpl=="function")return new Gf.promiseImpl(function($,z){try{A=U(f)(w),$(A)}catch(J){z(J)}});else throw new Error("Please provide a callback function");else{try{A=U(f)(w)}catch($){return g($)}g(null,A)}}function Bf(f){return Gf.fileLoader(f)}function J1(f,w){var g=Q.shallowCopy(Q.createNullProtoObjWherePossible(),w);if(g.filename=$1(f,g),typeof w.includer==="function"){var A=w.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 Qf(f,w,g,A,$){var z=w.split(`
|
|
14
|
+
`),J=Math.max(A-3,0),Y=Math.min(z.length,A+3),j=$(g),V=z.slice(J,Y).map(function(Z,F){var B=F+J+1;return(B==A?" >> ":" ")+B+"| "+Z}).join(`
|
|
15
15
|
`);throw f.path=j,f.message=(j||"ejs")+":"+A+`
|
|
16
16
|
`+V+`
|
|
17
17
|
|
|
18
|
-
`+f.message,f}function
|
|
18
|
+
`+f.message,f}function Xf(f){return f.replace(/;(\s*$)/,"$1")}Gf.compile=function f(w,g){var A;if(g&&g.scope){if(!Zf)console.warn("`scope` option is deprecated and will be removed in EJS 3"),Zf=!0;if(!g.context)g.context=g.scope;delete g.scope}return A=new X(w,g),A.compile()};Gf.render=function(f,w,g){var A=w||Q.createNullProtoObjWherePossible(),$=g||Q.createNullProtoObjWherePossible();if(arguments.length==2)Q.shallowCopyFromList($,A,Ff);return U($,f)(A)};Gf.renderFile=function(){var f=Array.prototype.slice.call(arguments),w=f.shift(),g,A={filename:w},$,z;if(typeof arguments[arguments.length-1]=="function")g=f.pop();if(f.length){if($=f.shift(),f.length)Q.shallowCopy(A,f.pop());else{if($.settings){if($.settings.views)A.views=$.settings.views;if($.settings["view cache"])A.cache=!0;if(z=$.settings["view options"],z)Q.shallowCopy(A,z)}Q.shallowCopyFromList(A,$,A1)}A.filename=w}else $=Q.createNullProtoObjWherePossible();return z1(A,$,g)};Gf.Template=X;Gf.clearCache=function(){Gf.cache.reset()};function X(f,w){var g=Q.hasOwnOnlyObject(w),A=Q.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||Q.escapeXML,A.compileDebug=g.compileDebug!==!1,A.debug=!!g.debug,A.filename=g.filename,A.openDelimiter=g.openDelimiter||Gf.openDelimiter||tf,A.closeDelimiter=g.closeDelimiter||Gf.closeDelimiter||ef,A.delimiter=g.delimiter||Gf.delimiter||f1,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||Gf.localsName||Cf,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()}X.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};X.prototype={createRegex:function(){var f=w1,w=Q.escapeRegExpChars(this.opts.delimiter),g=Q.escapeRegExpChars(this.opts.openDelimiter),A=Q.escapeRegExpChars(this.opts.closeDelimiter);return f=f.replace(/%/g,w).replace(/</g,g).replace(/>/g,A),new RegExp(f)},compile:function(){var f,w,g=this.opts,A="",$="",z=g.escapeFunction,J,Y=g.filename?JSON.stringify(g.filename):"undefined";if(!this.source){if(this.generateSource(),A+=` var __output = "";
|
|
19
19
|
function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
20
20
|
`,g.outputFunctionName){if(!q.test(g.outputFunctionName))throw new Error("outputFunctionName is not a valid JS identifier.");A+=" var "+g.outputFunctionName+` = __append;
|
|
21
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 j=" var __locals = ("+g.localsName+` || {}),
|
|
@@ -36,19 +36,19 @@ try {
|
|
|
36
36
|
`+f}if(g.strict)f=`"use strict";
|
|
37
37
|
`+f;if(g.debug)console.log(f);if(g.compileDebug&&g.filename)f=f+`
|
|
38
38
|
//# sourceURL=`+Y+`
|
|
39
|
-
`;try{if(g.async)try{J=new Function("return (async function(){}).constructor;")()}catch(
|
|
39
|
+
`;try{if(g.async)try{J=new Function("return (async function(){}).constructor;")()}catch(C){if(C instanceof SyntaxError)throw new Error("This environment does not support async/await");else throw C}else J=Function;w=new J(g.localsName+", escapeFn, include, rethrow",f)}catch(C){if(C instanceof SyntaxError){if(g.filename)C.message+=" in "+g.filename;if(C.message+=` while compiling ejs
|
|
40
40
|
|
|
41
|
-
`,
|
|
42
|
-
`,
|
|
43
|
-
`,
|
|
41
|
+
`,C.message+=`If the above error is not helpful, you may want to try EJS-Lint:
|
|
42
|
+
`,C.message+="https://github.com/RyanZim/EJS-Lint",!g.async)C.message+=`
|
|
43
|
+
`,C.message+="Or, if you meant to create an async function, pass `async: true` as an option."}throw C}var F=g.client?w:function C(I){var Hf=function(Nf,x){var O=Q.shallowCopy(Q.createNullProtoObjWherePossible(),I);if(x)O=Q.shallowCopy(O,x);return J1(Nf,g)(O)};return w.apply(g.context,[I||Q.createNullProtoObjWherePossible(),z,Hf,Qf])};if(g.filename&&typeof Object.defineProperty==="function"){var B=g.filename,G=R.basename(B,R.extname(B));try{Object.defineProperty(F,"name",{value:G,writable:!1,enumerable:!1,configurable:!0})}catch(C){}}return F},generateSource:function(){var f=this.opts;if(f.rmWhitespace)this.templateText=this.templateText.replace(/[\r\n]+/g,`
|
|
44
44
|
`).replace(/^\s+|\s+$/gm,"");this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var w=this,g=this.parseTemplateText(),A=this.opts.delimiter,$=this.opts.openDelimiter,z=this.opts.closeDelimiter;if(g&&g.length)g.forEach(function(J,Y){var j;if(J.indexOf($+A)===0&&J.indexOf($+A+A)!==0){if(j=g[Y+2],!(j==A+z||j=="-"+A+z||j=="_"+A+z))throw new Error('Could not find matching close tag for "'+J+'".')}w.scanLine(J)})},parseTemplateText:function(){var f=this.templateText,w=this.regex,g=w.exec(f),A=[],$;while(g){if($=g.index,$!==0)A.push(f.substring(0,$)),f=f.slice($);A.push(g[0]),f=f.slice(g[0].length),g=w.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
45
|
`},scanLine:function(f){var w=this,g=this.opts.delimiter,A=this.opts.openDelimiter,$=this.opts.closeDelimiter,z=0;switch(z=f.split(`
|
|
46
|
-
`).length-1,f){case A+g:case A+g+"_":this.mode=
|
|
47
|
-
`;break;case g+g+$:this.mode=
|
|
48
|
-
`;break;case g+$:case"-"+g+$:case"_"+g+$:if(this.mode==
|
|
46
|
+
`).length-1,f){case A+g:case A+g+"_":this.mode=X.modes.EVAL;break;case A+g+"=":this.mode=X.modes.ESCAPED;break;case A+g+"-":this.mode=X.modes.RAW;break;case A+g+"#":this.mode=X.modes.COMMENT;break;case A+g+g:this.mode=X.modes.LITERAL,this.source+=' ; __append("'+f.replace(A+g+g,A+g)+`")
|
|
47
|
+
`;break;case g+g+$:this.mode=X.modes.LITERAL,this.source+=' ; __append("'+f.replace(g+g+$,g+$)+`")
|
|
48
|
+
`;break;case g+$:case"-"+g+$:case"_"+g+$:if(this.mode==X.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 X.modes.EVAL:case X.modes.ESCAPED:case X.modes.RAW:if(f.lastIndexOf("//")>f.lastIndexOf(`
|
|
49
49
|
`))f+=`
|
|
50
|
-
`}switch(this.mode){case
|
|
51
|
-
`;break;case
|
|
52
|
-
`;break;case
|
|
53
|
-
`;break;case
|
|
54
|
-
`}};
|
|
50
|
+
`}switch(this.mode){case X.modes.EVAL:this.source+=" ; "+f+`
|
|
51
|
+
`;break;case X.modes.ESCAPED:this.source+=" ; __append(escapeFn("+Xf(f)+`))
|
|
52
|
+
`;break;case X.modes.RAW:this.source+=" ; __append("+Xf(f)+`)
|
|
53
|
+
`;break;case X.modes.COMMENT:break;case X.modes.LITERAL:this._addOutput(f);break}}else this._addOutput(f)}if(w.opts.compileDebug&&z)this.currentLine+=z,this.source+=" ; __line = "+this.currentLine+`
|
|
54
|
+
`}};Gf.escapeXML=Q.escapeXML;Gf.__express=Gf.renderFile;Gf.VERSION=pf;Gf.name=g1;if(typeof window!="undefined")window.ejs=Gf});function D(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 P=null;async function F1(){if(!P){let f=await Promise.resolve().then(() => bf(Uf(),1));P=f.default||f}return P}var G1={string:"text/plain; charset=utf-8",object:"application/json; charset=utf-8",Uint8Array:"application/octet-stream",ArrayBuffer:"application/octet-stream"};class _{req;server;path;routePattern;paramNames;env;executionContext;headers=new Headers;parsedQuery=null;parsedParams=null;parsedCookies=null;parsedBody=null;contextData={};urlObject=null;constructor(f,w,g,A,$,z,J){this.req=f,this.server=w,this.path=g,this.routePattern=A,this.executionContext=J,this.env=z,this.paramNames=$}setHeader(f,w){return this.headers.set(f,w),this}removeHeader(f){return this.headers.delete(f),this}set(f,w){return this.contextData[f]=w,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(!this.parsedParams)try{this.parsedParams=M1(this.paramNames,this.path)}catch(f){let w=f instanceof Error?f.message:String(f);throw new Error(`Failed to extract route parameters: ${w}`)}return this.parsedParams??{}}get body(){if(this.req.method==="GET")return Promise.resolve({});if(!this.parsedBody)this.parsedBody=(async()=>{try{let f=await R1(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,w=200){return new Response(f,{status:w,headers:this.headers})}send(f,w=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",G1[g]??"text/plain; charset=utf-8");let A=g==="object"&&f!==null?JSON.stringify(f):f;return new Response(A,{status:w,headers:this.headers})}json(f,w=200){return Response.json(f,{status:w,headers:this.headers})}file(f,w,g=200){let A=Bun.file(f);if(!this.headers.has("Content-Type"))this.headers.set("Content-Type",w??D(f));return new Response(A,{status:g,headers:this.headers})}async ejs(f,w={},g=200){let A=await F1();try{let $=await Bun.file(f).text(),z=A.render($,w),J=new Headers({"Content-Type":"text/html; charset=utf-8"});return new Response(z,{status:g,headers:J})}catch($){return console.error("EJS Rendering Error:",$),new Response("Error rendering template",{status:500})}}redirect(f,w=302){return this.headers.set("Location",f),new Response(null,{status:w,headers:this.headers})}setCookie(f,w,g={}){let A=`${encodeURIComponent(f)}=${encodeURIComponent(w)}`;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?W1(f):{}}return this.parsedCookies}stream(f){let w=new Headers(this.headers),g=new ReadableStream({async start(A){await f(A),A.close()}});return new Response(g,{headers:w})}yieldStream(f){return new Response}}function W1(f){return Object.fromEntries(f.split(";").map((w)=>{let[g,...A]=w.trim().split("=");return[g,decodeURIComponent(A.join("="))]}))}function M1(f,w){let g={},[A]=w.split("?"),$=A.split("/").filter((J)=>J!==""),z=$.length-f.length;for(let J=0;J<f.length;J++)g[f[J]]=$[z+J];return g}function c1(f,w){let g={},A=f.split("/"),[$]=w.split("?"),z=$.split("/");if(A.length!==z.length)return null;for(let J=0;J<A.length;J++){let Y=A[J];if(Y.charCodeAt(0)===58)g[Y.slice(1)]=z[J]}return g}async function R1(f){let w=f.headers.get("Content-Type")||"";if(!w)return{};if(f.headers.get("Content-Length")==="0"||!f.body)return{};if(w.startsWith("application/json"))return await f.json();if(w.startsWith("application/x-www-form-urlencoded")){let A=await f.text();return Object.fromEntries(new URLSearchParams(A))}if(w.startsWith("multipart/form-data")){let A=await f.formData(),$={};for(let[z,J]of A.entries())$[z]=J;return $}return{error:"Unknown request body type"}}var U1=(f,w)=>{try{return w(f)}catch{return f.replace(/(?:%[0-9A-Fa-f]{2})+/g,(g)=>{try{return w(g)}catch{return g}})}},y=(f)=>U1(f,decodeURI),_1=(f)=>{let w=f.indexOf("/",f.indexOf(":")+4),g=w;for(;g<f.length;g++){let A=f.charCodeAt(g);if(A===37){let $=f.indexOf("?",g),z=f.slice(w,$===-1?void 0:$);return y(z.includes("%25")?z.replace(/%25/g,"%2525"):z)}else if(A===63)break}return f.slice(w,g)};async function N(f,w,g){if(!w?.length)return;for(let A=0;A<w.length;A++){let $=w[A](...g),z=$ instanceof Promise?await $:$;if(z&&f!=="onRequest")return z}}async function Df(f,w,g){let A=f.globalMiddlewares;if(A.length)for(let z of A){let J=await z(g);if(J)return J}let $=f.middlewares.get(w);if($&&$.length)for(let z of $){let J=await z(g);if(J)return J}return null}async function I1(f,w,g){for(let A of f){let $=await A(w,g);if($)return $}}async function Kf(f,w,g){let A=await D1(f,w,g),$=A instanceof Promise?await A:A;if($)return $}async function D1(f,w,g){if(w.endsWith("/"))w=w.slice(0,-1);if(!f.filters.has(w))if(f.filterFunction.length)for(let A of f.filterFunction){let $=await A(g);if($)return $}else return Response.json({error:"Protected route, authentication required"},{status:401})}async function vf(f,w,g){if(f.staticPath){let $=!0;if(f.staticRequestPath)$=g.startsWith(f.staticRequestPath);if($){let z=await K1(f,g,w);if(z)return z;let J=f.router.find(w.req.method,"*");if(J?.handler)return await J.handler(w)}}let A=f.routeNotFoundFunc(w);return A instanceof Promise?await A:A||k(404,`404 Route not found for ${g}`)}function k(f,w){return new Response(JSON.stringify({error:w}),{status:f,headers:{"Content-Type":"application/json"}})}async function K1(f,w,g){if(!f.staticPath)return null;let A=`${f.staticPath}${w}`;if(await Bun.file(A).exists()){let z=D(A);return g.file(A,z,200)}return null}async function v1(f,w,g,A,$){let z,J=f.url.indexOf("/",f.url.indexOf(":")+4),Y=J;for(;Y<f.url.length;Y++){let B=f.url.charCodeAt(Y);if(B===37){let G=f.url.indexOf("?",Y),C=f.url.slice(J,G===-1?void 0:G);z=y(C.includes("%25")?C.replace(/%25/g,"%2525"):C);break}else if(B===63)break}if(!z)z=f.url.slice(J,Y);let j=g.router.find(f.method,z),V=new _(f,w,z,j?.path,A,$);if(g.hasOnReqHook)await N("onRequest",g.hooks.onRequest,[f,z,w]);if(g.hasMiddleware){let B=await Df(g,z,V);if(B)return B}if(g.hasFilterEnabled){let B=await Kf(g,z,V);if(B)return B}if(!j)return await vf(g,V,z);if(g.hasPreHandlerHook){let B=await N("preHandler",g.hooks.preHandler,[V]);if(B)return B}let Z=j.handler(V),F=Z instanceof Promise?await Z:Z;if(g.hasOnSendHook){let B=await N("onSend",g.hooks.onSend,[V,F]);if(B)return B}if(F instanceof Response)return F;return k(500,"No response returned from handler.")}export{v1 as default};
|
package/dist/main.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { CompileConfig, ContextType, corsT, FilterMethods, HookType, listenArgsT, middlewareFunc, RouteNotFoundHandler, type handlerFunction, type Hooks } from "./types.js";
|
|
1
|
+
import { CompileConfig, ContextType, corsT, DieselOptions, errorFormat, FilterMethods, HookType, listenArgsT, middlewareFunc, RouteNotFoundHandler, type handlerFunction, type Hooks } from "./types.js";
|
|
2
2
|
import { Server } from "bun";
|
|
3
3
|
import { AdvancedLoggerOptions, LoggerOptions } from "./middlewares/logger/logger.js";
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import { Router } from "./router/interface.js";
|
|
6
|
-
type errorFormat = 'json' | 'text' | 'html' | string;
|
|
7
6
|
export default class Diesel {
|
|
8
7
|
#private;
|
|
9
8
|
private static instance;
|
|
10
9
|
routes: Record<string, Function>;
|
|
11
10
|
private tempRoutes;
|
|
12
|
-
|
|
13
|
-
middlewares: Map<string, middlewareFunc[]>;
|
|
11
|
+
tempMiddlewares: Map<string, middlewareFunc[]> | null;
|
|
14
12
|
router: Router;
|
|
15
13
|
hasOnReqHook: boolean;
|
|
16
|
-
hasMiddleware: boolean;
|
|
17
14
|
hasPreHandlerHook: boolean;
|
|
18
15
|
hasPostHandlerHook: boolean;
|
|
19
16
|
hasOnSendHook: boolean;
|
|
@@ -38,19 +35,7 @@ export default class Diesel {
|
|
|
38
35
|
platform: string;
|
|
39
36
|
staticPath: any;
|
|
40
37
|
staticRequestPath: string | undefined;
|
|
41
|
-
constructor(
|
|
42
|
-
jwtSecret?: string;
|
|
43
|
-
baseApiUrl?: string;
|
|
44
|
-
enableFileRouting?: boolean;
|
|
45
|
-
idleTimeOut?: number;
|
|
46
|
-
prefixApiUrl?: string;
|
|
47
|
-
onError?: boolean;
|
|
48
|
-
logger?: boolean;
|
|
49
|
-
pipelineArchitecture?: boolean;
|
|
50
|
-
errorFormat?: errorFormat;
|
|
51
|
-
platform?: string;
|
|
52
|
-
router?: string;
|
|
53
|
-
});
|
|
38
|
+
constructor(options?: DieselOptions);
|
|
54
39
|
static router(prefix: string): Diesel;
|
|
55
40
|
/**
|
|
56
41
|
this filter is like user once specify which routes needs to be public and for rest routes use a global
|
|
@@ -87,12 +72,7 @@ export default class Diesel {
|
|
|
87
72
|
*/
|
|
88
73
|
route(basePath: string | undefined, routerInstance: Diesel | null): this;
|
|
89
74
|
/**
|
|
90
|
-
|
|
91
|
-
* Allows defining subroutes like:
|
|
92
|
-
* const userRoute = new Diesel();
|
|
93
|
-
* userRoute.post("/login",handlerFunction)
|
|
94
|
-
* userRoute.post("/register", handlerFunction)
|
|
95
|
-
* app.register("/api/v1/user", userRoute);
|
|
75
|
+
same as Route
|
|
96
76
|
*/
|
|
97
77
|
register(basePath: string | undefined, routerInstance: Diesel): this;
|
|
98
78
|
private addRoute;
|
|
@@ -103,23 +83,19 @@ export default class Diesel {
|
|
|
103
83
|
*
|
|
104
84
|
* Examples:
|
|
105
85
|
* - app.use(h1) -> Adds a single global middleware.
|
|
106
|
-
* - app.use([h1, h2]) -> Adds multiple global middlewares.
|
|
107
86
|
* - app.use("/home", h1) -> Adds `h1` middleware to the `/home` path.
|
|
108
|
-
* - app.use(["/home", "/user"], [h1, h2]) -> Adds `h1` and `h2` to `/home` and `/user`.
|
|
109
|
-
* - app.use(h1, [h2, h1]) -> Runs `h1`, then `h2`, and `h1` again as specified.
|
|
110
87
|
*/
|
|
111
88
|
use(pathORHandler?: string | string[] | middlewareFunc | middlewareFunc[] | Function | Function[], ...handlers: middlewareFunc | middlewareFunc[] | Function | Function[] | any): this;
|
|
112
|
-
get(path: string, ...handlers: handlerFunction[]): this;
|
|
113
|
-
post(path: string, ...handlers: handlerFunction[]): this;
|
|
114
|
-
put(path: string, ...handlers: handlerFunction[]): this;
|
|
115
|
-
patch(path: string, ...handlers: handlerFunction[]): this;
|
|
116
|
-
delete(path: string, ...handlers: handlerFunction[]): this;
|
|
117
|
-
any(path: string, ...handlers: handlerFunction[]): this;
|
|
118
|
-
head(path: string, ...handlers: handlerFunction[]): this;
|
|
119
|
-
options(path: string, ...handlers: handlerFunction[]): this;
|
|
120
|
-
propfind(path: string, ...handlers: handlerFunction[]): this;
|
|
89
|
+
get(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
90
|
+
post(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
91
|
+
put(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
92
|
+
patch(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
93
|
+
delete(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
94
|
+
any(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
95
|
+
head(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
96
|
+
options(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
97
|
+
propfind(path: string, ...handlers: handlerFunction[] | Function[]): this;
|
|
121
98
|
routeNotFound(handler: RouteNotFoundHandler): this;
|
|
122
99
|
on(event: string | symbol, listener: EventListener): void;
|
|
123
100
|
emit(event: string | symbol, ...args: any): void;
|
|
124
101
|
}
|
|
125
|
-
export {};
|