tezx 1.0.70 โ†’ 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.70";
10
+ exports.version = "1.0.71";
@@ -96,10 +96,10 @@ function sanitized(title) {
96
96
  const base = title
97
97
  .toLowerCase()
98
98
  .trim()
99
- .replace(/[_\s]+/g, '-')
100
- .replace(/[^a-z0-9-.]+/g, '')
101
- .replace(/--+/g, '-')
102
- .replace(/^-+|-+$/g, '');
99
+ .replace(/[_\s]+/g, "-")
100
+ .replace(/[^a-z0-9-.]+/g, "")
101
+ .replace(/--+/g, "-")
102
+ .replace(/^-+|-+$/g, "");
103
103
  return base;
104
104
  }
105
105
  async function parseMultipartBody(req, boundary, options) {
@@ -143,8 +143,7 @@ async function parseMultipartBody(req, boundary, options) {
143
143
  const fieldName = fieldNameMatch[1];
144
144
  const contentType = contentTypeMatch[1];
145
145
  if (options?.sanitized) {
146
- filename =
147
- `${Date.now()}-${sanitized(filename)}`;
146
+ filename = `${Date.now()}-${sanitized(filename)}`;
148
147
  }
149
148
  if (Array.isArray(options?.allowedTypes) &&
150
149
  !options.allowedTypes?.includes(contentType)) {
@@ -202,8 +201,7 @@ async function parseMultipartBody(req, boundary, options) {
202
201
  if (val instanceof File && typeof options == "object") {
203
202
  let filename = val.name;
204
203
  if (options?.sanitized) {
205
- filename =
206
- `${Date.now()}-${sanitized(filename)}`;
204
+ filename = `${Date.now()}-${sanitized(filename)}`;
207
205
  }
208
206
  if (Array.isArray(options?.allowedTypes) &&
209
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.70";
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.70",
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",
package/utils/formData.js CHANGED
@@ -89,10 +89,10 @@ export function sanitized(title) {
89
89
  const base = title
90
90
  .toLowerCase()
91
91
  .trim()
92
- .replace(/[_\s]+/g, '-')
93
- .replace(/[^a-z0-9-.]+/g, '')
94
- .replace(/--+/g, '-')
95
- .replace(/^-+|-+$/g, '');
92
+ .replace(/[_\s]+/g, "-")
93
+ .replace(/[^a-z0-9-.]+/g, "")
94
+ .replace(/--+/g, "-")
95
+ .replace(/^-+|-+$/g, "");
96
96
  return base;
97
97
  }
98
98
  export async function parseMultipartBody(req, boundary, options) {
@@ -136,8 +136,7 @@ export async function parseMultipartBody(req, boundary, options) {
136
136
  const fieldName = fieldNameMatch[1];
137
137
  const contentType = contentTypeMatch[1];
138
138
  if (options?.sanitized) {
139
- filename =
140
- `${Date.now()}-${sanitized(filename)}`;
139
+ filename = `${Date.now()}-${sanitized(filename)}`;
141
140
  }
142
141
  if (Array.isArray(options?.allowedTypes) &&
143
142
  !options.allowedTypes?.includes(contentType)) {
@@ -195,8 +194,7 @@ export async function parseMultipartBody(req, boundary, options) {
195
194
  if (val instanceof File && typeof options == "object") {
196
195
  let filename = val.name;
197
196
  if (options?.sanitized) {
198
- filename =
199
- `${Date.now()}-${sanitized(filename)}`;
197
+ filename = `${Date.now()}-${sanitized(filename)}`;
200
198
  }
201
199
  if (Array.isArray(options?.allowedTypes) &&
202
200
  !options.allowedTypes?.includes(val.type)) {