tezx 3.0.8-beta โ 3.0.9-beta
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/router.js +3 -12
- package/cjs/index.js +1 -1
- package/cjs/middleware/cache-control.js +5 -3
- package/cjs/registry/RadixRouter.js +0 -17
- package/core/router.js +3 -12
- package/index.js +1 -1
- package/middleware/cache-control.d.ts +8 -1
- package/middleware/cache-control.js +5 -3
- package/package.json +1 -1
- package/registry/RadixRouter.d.ts +0 -7
- package/registry/RadixRouter.js +0 -17
- package/types/index.d.ts +0 -1
package/cjs/core/router.js
CHANGED
|
@@ -174,18 +174,9 @@ class Router {
|
|
|
174
174
|
if (!(router instanceof Router)) {
|
|
175
175
|
throw new Error("Router instance is required.");
|
|
176
176
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.#addRoute(r?.method, `/${(0, low_level_js_1.sanitizePathSplitBasePath)(path, r?.pattern).join("/")}`, r?.handlers, true);
|
|
181
|
-
});
|
|
182
|
-
this.router.mergeRouter(`/${parts.join("/")}`, router.router);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
router.route.forEach((r) => {
|
|
186
|
-
this.#addRoute(r?.method, `/${(0, low_level_js_1.sanitizePathSplitBasePath)(path, r?.pattern).join("/")}`, r?.handlers);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
177
|
+
router.route.forEach((r) => {
|
|
178
|
+
this.#addRoute(r?.method, `/${(0, low_level_js_1.sanitizePathSplitBasePath)(path, r?.pattern).join("/")}`, r?.handlers);
|
|
179
|
+
});
|
|
189
180
|
Object.assign(this.staticFile, router.staticFile);
|
|
190
181
|
}
|
|
191
182
|
}
|
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 = "3.0.
|
|
8
|
+
exports.version = "3.0.9-beta";
|
|
9
9
|
exports.default = {
|
|
10
10
|
Router: router_js_1.Router,
|
|
11
11
|
TezX: server_js_1.TezX,
|
|
@@ -36,7 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.default = exports.cacheControl = void 0;
|
|
37
37
|
const config_js_1 = require("../core/config.js");
|
|
38
38
|
const cacheControl = (options) => {
|
|
39
|
-
const { defaultSettings, useWeakETag = false, rules = [],
|
|
39
|
+
const { defaultSettings, useWeakETag = false, rules = [], onError = (error, ctx) => {
|
|
40
|
+
ctx.setStatus = 500;
|
|
41
|
+
ctx.body = { error: "Failed to set cache headers." };
|
|
42
|
+
}, logEvent = (event, ctx, error) => {
|
|
40
43
|
if (event === "error") {
|
|
41
44
|
config_js_1.GlobalConfig.debugging.error(`[CACHE] ${event.toUpperCase()}: ${error?.message}`);
|
|
42
45
|
}
|
|
@@ -77,8 +80,7 @@ const cacheControl = (options) => {
|
|
|
77
80
|
}
|
|
78
81
|
catch (error) {
|
|
79
82
|
logEvent("error", ctx, error);
|
|
80
|
-
|
|
81
|
-
ctx.body = { error: "Failed to set cache headers." };
|
|
83
|
+
return onError?.(error, ctx);
|
|
82
84
|
}
|
|
83
85
|
};
|
|
84
86
|
};
|
|
@@ -102,23 +102,6 @@ class RadixRouter {
|
|
|
102
102
|
}
|
|
103
103
|
return { success: false, node };
|
|
104
104
|
}
|
|
105
|
-
mergeRouter(basePath, childRouter) {
|
|
106
|
-
const segments = (0, index_js_1.sanitizePathSplit)(basePath);
|
|
107
|
-
let node = this.root;
|
|
108
|
-
for (const segment of segments) {
|
|
109
|
-
node.children[segment] ??= { children: {} };
|
|
110
|
-
node = node.children[segment];
|
|
111
|
-
}
|
|
112
|
-
if (childRouter.root.handlers) {
|
|
113
|
-
node.isEndpoint = true;
|
|
114
|
-
node.handlers ??= {};
|
|
115
|
-
for (const method in childRouter.root.handlers) {
|
|
116
|
-
node.handlers[method] ??= [];
|
|
117
|
-
node.handlers[method].push(...(childRouter.root.handlers?.[method] || []));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
Object.assign(node.children, childRouter.root.children);
|
|
121
|
-
}
|
|
122
105
|
parsePattern(pattern) {
|
|
123
106
|
const segments = (0, index_js_1.sanitizePathSplit)(pattern);
|
|
124
107
|
const result = [];
|
package/core/router.js
CHANGED
|
@@ -171,18 +171,9 @@ export class Router {
|
|
|
171
171
|
if (!(router instanceof Router)) {
|
|
172
172
|
throw new Error("Router instance is required.");
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.#addRoute(r?.method, `/${sanitizePathSplitBasePath(path, r?.pattern).join("/")}`, r?.handlers, true);
|
|
178
|
-
});
|
|
179
|
-
this.router.mergeRouter(`/${parts.join("/")}`, router.router);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
router.route.forEach((r) => {
|
|
183
|
-
this.#addRoute(r?.method, `/${sanitizePathSplitBasePath(path, r?.pattern).join("/")}`, r?.handlers);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
174
|
+
router.route.forEach((r) => {
|
|
175
|
+
this.#addRoute(r?.method, `/${sanitizePathSplitBasePath(path, r?.pattern).join("/")}`, r?.handlers);
|
|
176
|
+
});
|
|
186
177
|
Object.assign(this.staticFile, router.staticFile);
|
|
187
178
|
}
|
|
188
179
|
}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "../core/context.js";
|
|
2
|
-
import { Middleware } from "../types/index.js";
|
|
2
|
+
import { HttpBaseResponse, Middleware } from "../types/index.js";
|
|
3
3
|
export type CacheRule = {
|
|
4
4
|
/**
|
|
5
5
|
* ๐ฏ Condition to determine if this rule applies.
|
|
@@ -28,6 +28,13 @@ export type CacheOptions = {
|
|
|
28
28
|
* ๐งช Weak ETag generation (optional).
|
|
29
29
|
*/
|
|
30
30
|
useWeakETag?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Error handler for cache middleware.
|
|
33
|
+
* @param error - The error that occurred.
|
|
34
|
+
* @param ctx - The current request context.
|
|
35
|
+
* @returns An HTTP response to send when an error occurs.
|
|
36
|
+
*/
|
|
37
|
+
onError?: (error: Error, ctx: Context) => HttpBaseResponse;
|
|
31
38
|
/**
|
|
32
39
|
* ๐ Logging function for cache events.
|
|
33
40
|
*/
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { GlobalConfig } from "../core/config.js";
|
|
2
2
|
const cacheControl = (options) => {
|
|
3
|
-
const { defaultSettings, useWeakETag = false, rules = [],
|
|
3
|
+
const { defaultSettings, useWeakETag = false, rules = [], onError = (error, ctx) => {
|
|
4
|
+
ctx.setStatus = 500;
|
|
5
|
+
ctx.body = { error: "Failed to set cache headers." };
|
|
6
|
+
}, logEvent = (event, ctx, error) => {
|
|
4
7
|
if (event === "error") {
|
|
5
8
|
GlobalConfig.debugging.error(`[CACHE] ${event.toUpperCase()}: ${error?.message}`);
|
|
6
9
|
}
|
|
@@ -41,8 +44,7 @@ const cacheControl = (options) => {
|
|
|
41
44
|
}
|
|
42
45
|
catch (error) {
|
|
43
46
|
logEvent("error", ctx, error);
|
|
44
|
-
|
|
45
|
-
ctx.body = { error: "Failed to set cache headers." };
|
|
47
|
+
return onError?.(error, ctx);
|
|
46
48
|
}
|
|
47
49
|
};
|
|
48
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9-beta",
|
|
4
4
|
"description": "TezX is a high-performance, lightweight JavaScript framework designed for speed, scalability, and flexibility. It enables efficient routing, middleware management, and static file serving with minimal configuration. Fully compatible with Node.js, Deno, and Bun.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -30,13 +30,6 @@ export declare class RadixRouter implements RouteRegistry {
|
|
|
30
30
|
* @private
|
|
31
31
|
*/
|
|
32
32
|
private _match;
|
|
33
|
-
/**
|
|
34
|
-
* Merges a child router under a given base path.
|
|
35
|
-
*
|
|
36
|
-
* @param basePath - The base route prefix to mount the child router
|
|
37
|
-
* @param childRouter - The child router to merge into this one
|
|
38
|
-
*/
|
|
39
|
-
mergeRouter(basePath: string, childRouter: this): void;
|
|
40
33
|
/**
|
|
41
34
|
* Parses a route pattern into structured segments.
|
|
42
35
|
*
|
package/registry/RadixRouter.js
CHANGED
|
@@ -99,23 +99,6 @@ export class RadixRouter {
|
|
|
99
99
|
}
|
|
100
100
|
return { success: false, node };
|
|
101
101
|
}
|
|
102
|
-
mergeRouter(basePath, childRouter) {
|
|
103
|
-
const segments = sanitizePathSplit(basePath);
|
|
104
|
-
let node = this.root;
|
|
105
|
-
for (const segment of segments) {
|
|
106
|
-
node.children[segment] ??= { children: {} };
|
|
107
|
-
node = node.children[segment];
|
|
108
|
-
}
|
|
109
|
-
if (childRouter.root.handlers) {
|
|
110
|
-
node.isEndpoint = true;
|
|
111
|
-
node.handlers ??= {};
|
|
112
|
-
for (const method in childRouter.root.handlers) {
|
|
113
|
-
node.handlers[method] ??= [];
|
|
114
|
-
node.handlers[method].push(...(childRouter.root.handlers?.[method] || []));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
Object.assign(node.children, childRouter.root.children);
|
|
118
|
-
}
|
|
119
102
|
parsePattern(pattern) {
|
|
120
103
|
const segments = sanitizePathSplit(pattern);
|
|
121
104
|
const result = [];
|
package/types/index.d.ts
CHANGED
|
@@ -346,7 +346,6 @@ export interface RouteRegistry {
|
|
|
346
346
|
* @param handlers - Array of middleware or callback handlers
|
|
347
347
|
*/
|
|
348
348
|
addRoute<T extends Record<string, any> = any>(method: HTTPMethod, path: string, handler: HandlerType<T>): void;
|
|
349
|
-
mergeRouter?(path: string, router: this): void;
|
|
350
349
|
/**
|
|
351
350
|
* Find a route based on the given method and path.
|
|
352
351
|
*
|