tezx 1.0.69 โ†’ 1.0.71

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.
@@ -36,21 +36,38 @@ class TezX extends router_js_1.Router {
36
36
  }
37
37
  return null;
38
38
  }
39
- #triRouter(method, pathname) {
39
+ #triRouter(method, pathname, priority = "static") {
40
40
  const parts = pathname.split("/").filter(Boolean);
41
41
  const params = {};
42
42
  let node = this.triRouter;
43
- for (let part of parts) {
44
- if (node.children.has(part)) {
45
- node = node.children.get(part);
46
- }
47
- else if (node.children.has(":")) {
48
- node = node.children.get(":");
49
- if (node.paramName)
50
- params[node.paramName] = part;
43
+ if (priority == "static") {
44
+ for (let part of parts) {
45
+ if (node.children.has(part)) {
46
+ node = node.children.get(part);
47
+ }
48
+ else if (node.children.has(":")) {
49
+ node = node.children.get(":");
50
+ if (node.paramName)
51
+ params[node.paramName] = part;
52
+ }
53
+ else {
54
+ return null;
55
+ }
51
56
  }
52
- else {
53
- return null;
57
+ }
58
+ else {
59
+ for (let part of parts) {
60
+ if (node.children.has(":")) {
61
+ node = node.children.get(":");
62
+ if (node.paramName)
63
+ params[node.paramName] = part;
64
+ }
65
+ else if (node.children.has(part)) {
66
+ node = node.children.get(part);
67
+ }
68
+ else {
69
+ return null;
70
+ }
54
71
  }
55
72
  }
56
73
  if (node?.handlers?.size && node?.pathname) {
@@ -67,7 +84,9 @@ class TezX extends router_js_1.Router {
67
84
  return null;
68
85
  }
69
86
  findRoute(method, pathname) {
70
- const route = this.#triRouter(method, pathname) || this.#hashRouter(method, pathname);
87
+ const route = this.#triRouter(method, pathname) ||
88
+ this.#hashRouter(method, pathname) ||
89
+ this.#triRouter(method, pathname, "param");
71
90
  if (route) {
72
91
  return {
73
92
  ...route,
@@ -163,6 +182,7 @@ class TezX extends router_js_1.Router {
163
182
  combine.push(...routeMiddlewares, callback);
164
183
  }
165
184
  else {
185
+ ctx.setStatus = 404;
166
186
  combine.push(config_js_1.GlobalConfig.notFound);
167
187
  }
168
188
  let response = await this.#createHandler(combine)(ctx);
package/cjs/index.js CHANGED
@@ -7,4 +7,4 @@ var server_js_1 = require("./core/server.js");
7
7
  Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
8
8
  var params_js_1 = require("./utils/params.js");
9
9
  Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
10
- exports.version = "1.0.69";
10
+ exports.version = "1.0.71";
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseJsonBody = parseJsonBody;
4
4
  exports.parseTextBody = parseTextBody;
5
5
  exports.parseUrlEncodedBody = parseUrlEncodedBody;
6
+ exports.sanitized = sanitized;
6
7
  exports.parseMultipartBody = parseMultipartBody;
7
8
  const config_js_1 = require("../core/config.js");
8
9
  async function parseJsonBody(req) {
@@ -91,6 +92,16 @@ async function parseUrlEncodedBody(req) {
91
92
  throw new Error("Unsupported environment for multipart parsing");
92
93
  }
93
94
  }
95
+ function sanitized(title) {
96
+ const base = title
97
+ .toLowerCase()
98
+ .trim()
99
+ .replace(/[_\s]+/g, "-")
100
+ .replace(/[^a-z0-9-.]+/g, "")
101
+ .replace(/--+/g, "-")
102
+ .replace(/^-+|-+$/g, "");
103
+ return base;
104
+ }
94
105
  async function parseMultipartBody(req, boundary, options) {
95
106
  const runtime = config_js_1.GlobalConfig.adapter;
96
107
  if (runtime === "node") {
@@ -132,8 +143,7 @@ async function parseMultipartBody(req, boundary, options) {
132
143
  const fieldName = fieldNameMatch[1];
133
144
  const contentType = contentTypeMatch[1];
134
145
  if (options?.sanitized) {
135
- filename =
136
- `${Date.now()}-${filename.replace(/\s+/g, "")?.replace(/[^a-zA-Z0-9.-]/g, "-")}`?.toLowerCase();
146
+ filename = `${Date.now()}-${sanitized(filename)}`;
137
147
  }
138
148
  if (Array.isArray(options?.allowedTypes) &&
139
149
  !options.allowedTypes?.includes(contentType)) {
@@ -191,8 +201,7 @@ async function parseMultipartBody(req, boundary, options) {
191
201
  if (val instanceof File && typeof options == "object") {
192
202
  let filename = val.name;
193
203
  if (options?.sanitized) {
194
- filename =
195
- `${Date.now()}-${filename.replace(/\s+/g, "")?.replace(/[^a-zA-Z0-9.-]/g, "-")}`?.toLowerCase();
204
+ filename = `${Date.now()}-${sanitized(filename)}`;
196
205
  }
197
206
  if (Array.isArray(options?.allowedTypes) &&
198
207
  !options.allowedTypes?.includes(val.type)) {
package/core/server.js CHANGED
@@ -33,21 +33,38 @@ export class TezX extends Router {
33
33
  }
34
34
  return null;
35
35
  }
36
- #triRouter(method, pathname) {
36
+ #triRouter(method, pathname, priority = "static") {
37
37
  const parts = pathname.split("/").filter(Boolean);
38
38
  const params = {};
39
39
  let node = this.triRouter;
40
- for (let part of parts) {
41
- if (node.children.has(part)) {
42
- node = node.children.get(part);
43
- }
44
- else if (node.children.has(":")) {
45
- node = node.children.get(":");
46
- if (node.paramName)
47
- params[node.paramName] = part;
40
+ if (priority == "static") {
41
+ for (let part of parts) {
42
+ if (node.children.has(part)) {
43
+ node = node.children.get(part);
44
+ }
45
+ else if (node.children.has(":")) {
46
+ node = node.children.get(":");
47
+ if (node.paramName)
48
+ params[node.paramName] = part;
49
+ }
50
+ else {
51
+ return null;
52
+ }
48
53
  }
49
- else {
50
- return null;
54
+ }
55
+ else {
56
+ for (let part of parts) {
57
+ if (node.children.has(":")) {
58
+ node = node.children.get(":");
59
+ if (node.paramName)
60
+ params[node.paramName] = part;
61
+ }
62
+ else if (node.children.has(part)) {
63
+ node = node.children.get(part);
64
+ }
65
+ else {
66
+ return null;
67
+ }
51
68
  }
52
69
  }
53
70
  if (node?.handlers?.size && node?.pathname) {
@@ -64,7 +81,9 @@ export class TezX extends Router {
64
81
  return null;
65
82
  }
66
83
  findRoute(method, pathname) {
67
- const route = this.#triRouter(method, pathname) || this.#hashRouter(method, pathname);
84
+ const route = this.#triRouter(method, pathname) ||
85
+ this.#hashRouter(method, pathname) ||
86
+ this.#triRouter(method, pathname, "param");
68
87
  if (route) {
69
88
  return {
70
89
  ...route,
@@ -160,6 +179,7 @@ export class TezX extends Router {
160
179
  combine.push(...routeMiddlewares, callback);
161
180
  }
162
181
  else {
182
+ ctx.setStatus = 404;
163
183
  combine.push(GlobalConfig.notFound);
164
184
  }
165
185
  let response = await this.#createHandler(combine)(ctx);
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Router } from "./core/router.js";
2
2
  export { TezX } from "./core/server.js";
3
3
  export { useParams } from "./utils/params.js";
4
- export let version = "1.0.69";
4
+ export let version = "1.0.71";
@@ -24,8 +24,8 @@ export type CacheRule = {
24
24
  export type CacheSettings = Pick<CacheRule, "maxAge" | "scope" | "enableETag" | "vary">;
25
25
  export type CacheOptions = {
26
26
  /**
27
- * ๐Ÿงช Weak ETag generation (optional).
28
- */
27
+ * ๐Ÿงช Weak ETag generation (optional).
28
+ */
29
29
  useWeakETag?: boolean;
30
30
  /**
31
31
  * ๐Ÿ“ Logging function for cache events.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tezx",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
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
  "main": "cjs/index.js",
6
6
  "module": "index.js",
@@ -2,4 +2,5 @@ import { FormDataOptions } from "../core/request.js";
2
2
  export declare function parseJsonBody(req: any): Promise<Record<string, any>>;
3
3
  export declare function parseTextBody(req: any): Promise<string>;
4
4
  export declare function parseUrlEncodedBody(req: any): Promise<Record<string, any>>;
5
+ export declare function sanitized(title: string): string;
5
6
  export declare function parseMultipartBody(req: any, boundary: string, options?: FormDataOptions): Promise<Record<string, any>>;
package/utils/formData.js CHANGED
@@ -85,6 +85,16 @@ export async function parseUrlEncodedBody(req) {
85
85
  throw new Error("Unsupported environment for multipart parsing");
86
86
  }
87
87
  }
88
+ export function sanitized(title) {
89
+ const base = title
90
+ .toLowerCase()
91
+ .trim()
92
+ .replace(/[_\s]+/g, "-")
93
+ .replace(/[^a-z0-9-.]+/g, "")
94
+ .replace(/--+/g, "-")
95
+ .replace(/^-+|-+$/g, "");
96
+ return base;
97
+ }
88
98
  export async function parseMultipartBody(req, boundary, options) {
89
99
  const runtime = GlobalConfig.adapter;
90
100
  if (runtime === "node") {
@@ -126,8 +136,7 @@ export async function parseMultipartBody(req, boundary, options) {
126
136
  const fieldName = fieldNameMatch[1];
127
137
  const contentType = contentTypeMatch[1];
128
138
  if (options?.sanitized) {
129
- filename =
130
- `${Date.now()}-${filename.replace(/\s+/g, "")?.replace(/[^a-zA-Z0-9.-]/g, "-")}`?.toLowerCase();
139
+ filename = `${Date.now()}-${sanitized(filename)}`;
131
140
  }
132
141
  if (Array.isArray(options?.allowedTypes) &&
133
142
  !options.allowedTypes?.includes(contentType)) {
@@ -185,8 +194,7 @@ export async function parseMultipartBody(req, boundary, options) {
185
194
  if (val instanceof File && typeof options == "object") {
186
195
  let filename = val.name;
187
196
  if (options?.sanitized) {
188
- filename =
189
- `${Date.now()}-${filename.replace(/\s+/g, "")?.replace(/[^a-zA-Z0-9.-]/g, "-")}`?.toLowerCase();
197
+ filename = `${Date.now()}-${sanitized(filename)}`;
190
198
  }
191
199
  if (Array.isArray(options?.allowedTypes) &&
192
200
  !options.allowedTypes?.includes(val.type)) {