tezx 4.0.7 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/core/context.js +1 -10
- package/cjs/core/router.js +3 -3
- package/cjs/index.js +1 -1
- package/cjs/middleware/logger.js +1 -1
- package/core/context.js +2 -11
- package/core/router.d.ts +1 -1
- package/core/router.js +3 -3
- package/index.js +1 -1
- package/middleware/logger.js +1 -1
- package/package.json +1 -1
package/cjs/core/context.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Context = void 0;
|
|
4
4
|
const mimeTypes_js_1 = require("../utils/mimeTypes.js");
|
|
5
5
|
const response_js_1 = require("../utils/response.js");
|
|
6
|
-
const utils_js_1 = require("../utils/utils.js");
|
|
7
6
|
const request_js_1 = require("./request.js");
|
|
8
7
|
class Context {
|
|
9
8
|
#status = 200;
|
|
@@ -89,15 +88,7 @@ class Context {
|
|
|
89
88
|
if (init?.filename) {
|
|
90
89
|
headers["Content-Disposition"] = `attachment; filename="${init?.filename}"`;
|
|
91
90
|
}
|
|
92
|
-
|
|
93
|
-
if (init?.download || init?.filename) {
|
|
94
|
-
contentType = "application/octet-stream";
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const ext = (0, utils_js_1.extensionExtract)(filePath);
|
|
98
|
-
contentType = mimeTypes_js_1.mimeTypes[ext] ?? mimeTypes_js_1.defaultMimeType;
|
|
99
|
-
}
|
|
100
|
-
return this.createResponse(stream, contentType, {
|
|
91
|
+
return this.createResponse(stream, (init?.download || init?.filename) ? "application/octet-stream" : file?.type ?? mimeTypes_js_1.defaultMimeType, {
|
|
101
92
|
status: init?.status ?? this.#status,
|
|
102
93
|
statusText: init?.statusText,
|
|
103
94
|
headers,
|
package/cjs/core/router.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.Router = void 0;
|
|
|
4
4
|
const url_js_1 = require("../utils/url.js");
|
|
5
5
|
class Router {
|
|
6
6
|
router;
|
|
7
|
-
|
|
7
|
+
routes = [];
|
|
8
8
|
staticFile = Object.create(null);
|
|
9
9
|
basePath;
|
|
10
10
|
constructor({ basePath = "/" } = {}) {
|
|
@@ -150,7 +150,7 @@ class Router {
|
|
|
150
150
|
#addRoute(method, path, handlers) {
|
|
151
151
|
let pattern = `/${(0, url_js_1.sanitizePathSplitBasePath)(this.basePath, path).join("/")}`;
|
|
152
152
|
this.router?.addRoute?.(method, pattern, handlers);
|
|
153
|
-
this.
|
|
153
|
+
this.routes.push({
|
|
154
154
|
method: method,
|
|
155
155
|
pattern: pattern,
|
|
156
156
|
handlers: handlers,
|
|
@@ -186,7 +186,7 @@ class Router {
|
|
|
186
186
|
if (!(router instanceof Router)) {
|
|
187
187
|
throw new Error("Router instance is required.");
|
|
188
188
|
}
|
|
189
|
-
router.
|
|
189
|
+
router.routes.forEach((r) => {
|
|
190
190
|
this.#addRoute(r?.method, `/${(0, url_js_1.sanitizePathSplitBasePath)(path, r?.pattern).join("/")}`, r?.handlers);
|
|
191
191
|
});
|
|
192
192
|
Object.assign(this.staticFile, router.staticFile);
|
package/cjs/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const router_js_1 = require("./core/router.js");
|
|
|
5
5
|
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_js_1.Router; } });
|
|
6
6
|
const server_js_1 = require("./core/server.js");
|
|
7
7
|
Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
|
|
8
|
-
exports.version = "4.0.
|
|
8
|
+
exports.version = "4.0.9";
|
|
9
9
|
exports.default = {
|
|
10
10
|
Router: router_js_1.Router,
|
|
11
11
|
TezX: server_js_1.TezX,
|
package/cjs/middleware/logger.js
CHANGED
|
@@ -11,7 +11,7 @@ function logger(options = { enabled: true }) {
|
|
|
11
11
|
}
|
|
12
12
|
console.log(`${(0, colors_js_1.colorText)("<--", "bold")} ${(0, colors_js_1.colorText)(ctx.method, "bgMagenta")} ${ctx.pathname}`);
|
|
13
13
|
const startTime = performance.now();
|
|
14
|
-
let n = (await next());
|
|
14
|
+
let n = (await next?.());
|
|
15
15
|
const elapsed = performance.now() - startTime;
|
|
16
16
|
console.log(`${(0, colors_js_1.colorText)("-->", "bold")} ${(0, colors_js_1.colorText)(ctx.method, "bgBlue")} ${ctx.pathname} ` +
|
|
17
17
|
`${(0, colors_js_1.colorText)(ctx.res?.status ?? 404, "yellow")} ${(0, colors_js_1.colorText)(`${elapsed.toFixed(2)}ms`, "magenta")}`);
|
package/core/context.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { defaultMimeType
|
|
1
|
+
import { defaultMimeType } from "../utils/mimeTypes.js";
|
|
2
2
|
import { mergeHeaders } from "../utils/response.js";
|
|
3
|
-
import { extensionExtract } from "../utils/utils.js";
|
|
4
3
|
import { TezXRequest } from "./request.js";
|
|
5
4
|
export class Context {
|
|
6
5
|
#status = 200;
|
|
@@ -86,15 +85,7 @@ export class Context {
|
|
|
86
85
|
if (init?.filename) {
|
|
87
86
|
headers["Content-Disposition"] = `attachment; filename="${init?.filename}"`;
|
|
88
87
|
}
|
|
89
|
-
|
|
90
|
-
if (init?.download || init?.filename) {
|
|
91
|
-
contentType = "application/octet-stream";
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const ext = extensionExtract(filePath);
|
|
95
|
-
contentType = mimeTypes[ext] ?? defaultMimeType;
|
|
96
|
-
}
|
|
97
|
-
return this.createResponse(stream, contentType, {
|
|
88
|
+
return this.createResponse(stream, (init?.download || init?.filename) ? "application/octet-stream" : file?.type ?? defaultMimeType, {
|
|
98
89
|
status: init?.status ?? this.#status,
|
|
99
90
|
statusText: init?.statusText,
|
|
100
91
|
headers,
|
package/core/router.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class Router<T extends Record<string, any> = {}> {
|
|
|
23
23
|
/** Internal route registry to hold all routes */
|
|
24
24
|
protected router?: RouteRegistry;
|
|
25
25
|
/** Array tracking registered routes and their handlers */
|
|
26
|
-
protected
|
|
26
|
+
protected routes: {
|
|
27
27
|
method: string;
|
|
28
28
|
pattern: string;
|
|
29
29
|
handlers: HandlerType;
|
package/core/router.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sanitizePathSplitBasePath } from "../utils/url.js";
|
|
2
2
|
export class Router {
|
|
3
3
|
router;
|
|
4
|
-
|
|
4
|
+
routes = [];
|
|
5
5
|
staticFile = Object.create(null);
|
|
6
6
|
basePath;
|
|
7
7
|
constructor({ basePath = "/" } = {}) {
|
|
@@ -147,7 +147,7 @@ export class Router {
|
|
|
147
147
|
#addRoute(method, path, handlers) {
|
|
148
148
|
let pattern = `/${sanitizePathSplitBasePath(this.basePath, path).join("/")}`;
|
|
149
149
|
this.router?.addRoute?.(method, pattern, handlers);
|
|
150
|
-
this.
|
|
150
|
+
this.routes.push({
|
|
151
151
|
method: method,
|
|
152
152
|
pattern: pattern,
|
|
153
153
|
handlers: handlers,
|
|
@@ -183,7 +183,7 @@ export class Router {
|
|
|
183
183
|
if (!(router instanceof Router)) {
|
|
184
184
|
throw new Error("Router instance is required.");
|
|
185
185
|
}
|
|
186
|
-
router.
|
|
186
|
+
router.routes.forEach((r) => {
|
|
187
187
|
this.#addRoute(r?.method, `/${sanitizePathSplitBasePath(path, r?.pattern).join("/")}`, r?.handlers);
|
|
188
188
|
});
|
|
189
189
|
Object.assign(this.staticFile, router.staticFile);
|
package/index.js
CHANGED
package/middleware/logger.js
CHANGED
|
@@ -7,7 +7,7 @@ function logger(options = { enabled: true }) {
|
|
|
7
7
|
}
|
|
8
8
|
console.log(`${colorText("<--", "bold")} ${colorText(ctx.method, "bgMagenta")} ${ctx.pathname}`);
|
|
9
9
|
const startTime = performance.now();
|
|
10
|
-
let n = (await next());
|
|
10
|
+
let n = (await next?.());
|
|
11
11
|
const elapsed = performance.now() - startTime;
|
|
12
12
|
console.log(`${colorText("-->", "bold")} ${colorText(ctx.method, "bgBlue")} ${ctx.pathname} ` +
|
|
13
13
|
`${colorText(ctx.res?.status ?? 404, "yellow")} ${colorText(`${elapsed.toFixed(2)}ms`, "magenta")}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.9",
|
|
4
4
|
"description": "TezX is a modern, ultra-lightweight, and high-performance JavaScript framework built specifically for Bun. It provides a minimal yet powerful API, seamless environment management, and a high-concurrency HTTP engine for building fast, scalable web applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "cjs/index.js",
|