tezx 1.0.73 → 1.0.75-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.
Files changed (76) hide show
  1. package/adapter/bun.d.ts +29 -0
  2. package/adapter/deno.d.ts +30 -0
  3. package/adapter/index.d.ts +1 -1
  4. package/adapter/index.js +1 -1
  5. package/adapter/node/index.d.ts +47 -0
  6. package/adapter/{node.js → node/index.js} +2 -2
  7. package/cjs/adapter/index.js +1 -1
  8. package/cjs/adapter/{node.js → node/index.js} +2 -2
  9. package/cjs/core/context.js +13 -97
  10. package/cjs/core/environment.js +0 -8
  11. package/cjs/core/request.js +69 -25
  12. package/cjs/core/router.js +5 -0
  13. package/cjs/core/server.js +6 -5
  14. package/cjs/index.js +1 -1
  15. package/cjs/middleware/basicAuth.js +1 -1
  16. package/cjs/middleware/cacheControl.js +1 -1
  17. package/cjs/middleware/cors.js +2 -2
  18. package/cjs/middleware/detectBot.js +1 -1
  19. package/cjs/middleware/detectLocale.js +1 -1
  20. package/cjs/middleware/{i18nMiddleware.js → i18n.js} +4 -4
  21. package/cjs/middleware/index.js +1 -1
  22. package/cjs/middleware/lazyLoadModules.js +1 -1
  23. package/cjs/middleware/logger.js +1 -1
  24. package/cjs/middleware/pagination.js +1 -1
  25. package/cjs/middleware/powered-by.js +1 -1
  26. package/cjs/middleware/rateLimiter.js +1 -1
  27. package/cjs/middleware/request-id.js +1 -1
  28. package/cjs/middleware/requestTimeout.js +1 -1
  29. package/cjs/middleware/sanitizeHeader.js +3 -3
  30. package/cjs/middleware/secureHeaders.js +1 -1
  31. package/cjs/middleware/xssProtection.js +1 -1
  32. package/cjs/utils/formData.js +0 -235
  33. package/cjs/utils/httpStatusMap.js +68 -0
  34. package/cjs/utils/staticFile.js +4 -1
  35. package/cjs/utils/toWebRequest.js +35 -0
  36. package/core/context.d.ts +5 -6
  37. package/core/context.js +14 -98
  38. package/core/environment.d.ts +0 -2
  39. package/core/environment.js +0 -8
  40. package/core/request.d.ts +11 -32
  41. package/core/request.js +70 -26
  42. package/core/router.d.ts +30 -0
  43. package/core/router.js +5 -0
  44. package/core/server.js +5 -4
  45. package/index.js +1 -1
  46. package/middleware/basicAuth.js +1 -1
  47. package/middleware/cacheControl.js +1 -1
  48. package/middleware/cors.js +2 -2
  49. package/middleware/detectBot.js +1 -1
  50. package/middleware/detectLocale.js +1 -1
  51. package/middleware/{i18nMiddleware.d.ts → i18n.d.ts} +3 -3
  52. package/middleware/{i18nMiddleware.js → i18n.js} +2 -2
  53. package/middleware/index.d.ts +1 -1
  54. package/middleware/index.js +1 -1
  55. package/middleware/lazyLoadModules.js +1 -1
  56. package/middleware/logger.js +1 -1
  57. package/middleware/pagination.js +1 -1
  58. package/middleware/powered-by.js +1 -1
  59. package/middleware/rateLimiter.js +1 -1
  60. package/middleware/request-id.js +1 -1
  61. package/middleware/requestTimeout.js +1 -1
  62. package/middleware/sanitizeHeader.js +3 -3
  63. package/middleware/secureHeaders.js +1 -1
  64. package/middleware/xssProtection.js +1 -1
  65. package/package.json +1 -1
  66. package/utils/formData.d.ts +0 -5
  67. package/utils/formData.js +0 -231
  68. package/utils/httpStatusMap.d.ts +1 -0
  69. package/utils/httpStatusMap.js +65 -0
  70. package/utils/staticFile.js +4 -1
  71. package/utils/toWebRequest.d.ts +11 -0
  72. package/utils/toWebRequest.js +32 -0
  73. package/adapter/node.d.ts +0 -19
  74. package/cjs/core/header.js +0 -92
  75. package/core/header.d.ts +0 -77
  76. package/core/header.js +0 -88
package/adapter/bun.d.ts CHANGED
@@ -1,4 +1,33 @@
1
1
  import { TezX } from "../core/server.js";
2
+ /**
3
+ * Starts the TezX server using Bun's built-in HTTP server.
4
+ *
5
+ * Supports Unix socket or TCP port, TLS options, hot reloading, error handling,
6
+ * WebSocket upgrade, and other Bun-specific server features.
7
+ *
8
+ * ### Usage examples:
9
+ * ```ts
10
+ * // Start server on port 3000
11
+ * bunAdapter(app).listen(3000, () => {
12
+ * console.log("Bun server running on port 3000");
13
+ * });
14
+ *
15
+ * // Start Unix socket server
16
+ * bunAdapter(app, { unix: "/tmp/tezx.sock" }).listen();
17
+ *
18
+ * // Start server with TLS and custom error handler
19
+ * bunAdapter(app, {
20
+ * port: 443,
21
+ * tls: { certFile: "./cert.pem", keyFile: "./key.pem" },
22
+ * error: (server, err) => new Response("Custom error", { status: 500 }),
23
+ * }).listen();
24
+ * ```
25
+ *
26
+ * @param {number} [port] - The TCP port number to listen on (ignored if unix socket is used).
27
+ * @param {(message: string) => void} [callback] - Optional callback invoked once the server starts.
28
+ * @returns {ReturnType<typeof Bun.serve>} Bun server instance.
29
+ * @throws {Error} Throws if Bun runtime is not detected.
30
+ */
2
31
  export declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>, options?: {
3
32
  /**
4
33
  * If set, the HTTP server will listen on a unix socket instead of a port.
package/adapter/deno.d.ts CHANGED
@@ -1,4 +1,34 @@
1
1
  import { TezX } from "../core/server.js";
2
+ /**
3
+ * Starts the TezX server using Deno's built-in serve APIs.
4
+ *
5
+ * Automatically selects between Unix socket and TCP server based on options.
6
+ * Supports TLS if TLS options are provided.
7
+ *
8
+ * ### Usage examples:
9
+ * ```ts
10
+ * // Start TCP server on port 3000
11
+ * denoAdapter(app).listen(3000, () => {
12
+ * console.log("Server running on port 3000");
13
+ * });
14
+ *
15
+ * // Start Unix socket server
16
+ * denoAdapter(app, { transport: "unix", path: "/tmp/tezx.sock" }).listen(() => {
17
+ * console.log("Server running on unix socket");
18
+ * });
19
+ *
20
+ * // With TLS
21
+ * denoAdapter(app, {
22
+ * port: 443,
23
+ * cert: Deno.readTextFileSync("./cert.pem"),
24
+ * key: Deno.readTextFileSync("./key.pem"),
25
+ * }).listen();
26
+ * ```
27
+ *
28
+ * @param {number} [port] - TCP port number to listen on (ignored if using Unix socket).
29
+ * @param {(message: string) => void} [callback] - Optional callback invoked after server starts.
30
+ * @returns {Deno.Listener | Deno.Server | null} Returns the server instance or null if Deno runtime is not detected.
31
+ */
2
32
  export declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>, options?: Deno.ServeUnixOptions | Deno.ServeTcpOptions | (Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem)): {
3
33
  listen: {
4
34
  (callback?: (message: string) => void): any;
@@ -1,4 +1,4 @@
1
1
  export type AdapterType = "bun" | "deno" | "node";
2
2
  export * from "./bun.js";
3
3
  export * from "./deno.js";
4
- export * from "./node.js";
4
+ export * from "./node/index.js";
package/adapter/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./bun.js";
2
2
  export * from "./deno.js";
3
- export * from "./node.js";
3
+ export * from "./node/index.js";
@@ -0,0 +1,47 @@
1
+ import type { ServerOptions } from "node:http";
2
+ import type { TlsOptions } from "node:tls";
3
+ import { TezX } from "../../core/server.js";
4
+ type UnixSocketOptions = ServerOptions & {
5
+ unix?: string;
6
+ enableSSL?: false;
7
+ };
8
+ type SSLOptions = ServerOptions & TlsOptions & {
9
+ enableSSL: true;
10
+ };
11
+ type TezXServerOptions = UnixSocketOptions | SSLOptions;
12
+ /**
13
+ * Starts the TezX server using Node.js native `http` or `https` module based on the `enableSSL` flag.
14
+ * - If `enableSSL` is true and valid TLS options are provided, it uses `https.createServer`.
15
+ * - Otherwise, falls back to `http.createServer`.
16
+ * - Optionally supports binding to a Unix domain socket via `options.unix`.
17
+ *
18
+ * ### Usage:
19
+ *
20
+ * ```ts
21
+ * // Start with default HTTP
22
+ * nodeAdapter(app).listen(3000, () => {
23
+ * console.log("Server is running");
24
+ * });
25
+ *
26
+ * // Start with HTTPS
27
+ * nodeAdapter(app, {
28
+ * enableSSL: true,
29
+ * key: fs.readFileSync("key.pem"),
30
+ * cert: fs.readFileSync("cert.pem")
31
+ * }).listen(443);
32
+ *
33
+ * // Start with Unix socket
34
+ * nodeAdapter(app, { unix: "/tmp/tezx.sock" }).listen();
35
+ * ```
36
+ * @param {number} [port] - The port number to listen on (ignored if `unix` is provided).
37
+ * @param {() => void} [callback] - Callback invoked after the server starts listening.
38
+ * @returns {void} Nothing is returned directly; server instance is stored in GlobalConfig.
39
+ */
40
+ export declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>, options?: TezXServerOptions): {
41
+ listen: {
42
+ (callback?: () => void): any;
43
+ (port?: number): any;
44
+ (port?: number, callback?: () => void): any;
45
+ };
46
+ };
47
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { Buffer } from "node:buffer";
2
- import { GlobalConfig } from "../core/config.js";
3
- import { Context } from "../core/context.js";
2
+ import { GlobalConfig } from "../../core/config.js";
3
+ import { Context } from "../../core/context.js";
4
4
  export function nodeAdapter(TezX, options = {}) {
5
5
  function listen(...arg) {
6
6
  let ssl = options?.enableSSL;
@@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./bun.js"), exports);
18
18
  __exportStar(require("./deno.js"), exports);
19
- __exportStar(require("./node.js"), exports);
19
+ __exportStar(require("./node/index.js"), exports);
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nodeAdapter = nodeAdapter;
4
4
  const node_buffer_1 = require("node:buffer");
5
- const config_js_1 = require("../core/config.js");
6
- const context_js_1 = require("../core/context.js");
5
+ const config_js_1 = require("../../core/config.js");
6
+ const context_js_1 = require("../../core/context.js");
7
7
  function nodeAdapter(TezX, options = {}) {
8
8
  function listen(...arg) {
9
9
  let ssl = options?.enableSSL;
@@ -1,82 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Context = exports.httpStatusMap = void 0;
3
+ exports.Context = void 0;
4
4
  const state_js_1 = require("../utils/state.js");
5
5
  const staticFile_js_1 = require("../utils/staticFile.js");
6
- const url_js_1 = require("../utils/url.js");
6
+ const toWebRequest_js_1 = require("../utils/toWebRequest.js");
7
7
  const config_js_1 = require("./config.js");
8
8
  const environment_js_1 = require("./environment.js");
9
- const header_js_1 = require("./header.js");
10
9
  const request_js_1 = require("./request.js");
11
- exports.httpStatusMap = {
12
- 100: "Continue",
13
- 101: "Switching Protocols",
14
- 102: "Processing",
15
- 103: "Early Hints",
16
- 200: "OK",
17
- 201: "Created",
18
- 202: "Accepted",
19
- 203: "Non-Authoritative Information",
20
- 204: "No Content",
21
- 205: "Reset Content",
22
- 206: "Partial Content",
23
- 207: "Multi-Status",
24
- 208: "Already Reported",
25
- 226: "IM Used",
26
- 300: "Multiple Choices",
27
- 301: "Moved Permanently",
28
- 302: "Found",
29
- 303: "See Other",
30
- 304: "Not Modified",
31
- 305: "Use Proxy",
32
- 306: "Switch Proxy",
33
- 307: "Temporary Redirect",
34
- 308: "Permanent Redirect",
35
- 400: "Bad Request",
36
- 401: "Unauthorized",
37
- 402: "Payment Required",
38
- 403: "Forbidden",
39
- 404: "Not Found",
40
- 405: "Method Not Allowed",
41
- 406: "Not Acceptable",
42
- 407: "Proxy Authentication Required",
43
- 408: "Request Timeout",
44
- 409: "Conflict",
45
- 410: "Gone",
46
- 411: "Length Required",
47
- 412: "Precondition Failed",
48
- 413: "Payload Too Large",
49
- 414: "URI Too Long",
50
- 415: "Unsupported Media Type",
51
- 416: "Range Not Satisfiable",
52
- 417: "Expectation Failed",
53
- 418: "I'm a Teapot",
54
- 421: "Misdirected Request",
55
- 422: "Unprocessable Entity",
56
- 423: "Locked",
57
- 424: "Failed Dependency",
58
- 425: "Too Early",
59
- 426: "Upgrade Required",
60
- 428: "Precondition Required",
61
- 429: "Too Many Requests",
62
- 431: "Request Header Fields Too Large",
63
- 451: "Unavailable For Legal Reasons",
64
- 500: "Internal Server Error",
65
- 501: "Not Implemented",
66
- 502: "Bad Gateway",
67
- 503: "Service Unavailable",
68
- 504: "Gateway Timeout",
69
- 505: "HTTP Version Not Supported",
70
- 506: "Variant Also Negotiates",
71
- 507: "Insufficient Storage",
72
- 508: "Loop Detected",
73
- 510: "Not Extended",
74
- 511: "Network Authentication Required",
75
- };
76
10
  class Context {
77
- #rawRequest;
11
+ rawRequest;
78
12
  env = {};
79
- headers = new header_js_1.HeadersParser();
13
+ headers = new Headers();
80
14
  pathname;
81
15
  url;
82
16
  method;
@@ -85,30 +19,20 @@ class Context {
85
19
  #params = {};
86
20
  resBody;
87
21
  #body;
88
- #urlRef;
89
- #requestHeaders;
90
22
  #options;
91
23
  constructor(req, options) {
92
24
  this.#options = options;
93
- this.#rawRequest = req;
94
25
  this.method = req?.method?.toUpperCase();
95
- this.#requestHeaders = new header_js_1.HeadersParser(req?.headers);
96
26
  if (config_js_1.GlobalConfig.adapter == "node") {
97
- let encrypted = req?.socket?.encrypted;
98
- const protocol = typeof encrypted === "boolean"
99
- ? encrypted
100
- ? "https"
101
- : "http"
102
- : "http";
103
- const host = environment_js_1.EnvironmentDetector.getHost(this.#requestHeaders);
104
- const path = req.url || "/";
105
- this.url = `${protocol}://${host}${path}`;
27
+ let request = (0, toWebRequest_js_1.toWebRequest)(req, this.method);
28
+ this.url = request.url;
29
+ this.rawRequest = request;
106
30
  }
107
31
  else {
108
32
  this.url = req.url;
33
+ this.rawRequest = req;
109
34
  }
110
- this.#urlRef = (0, url_js_1.urlParse)(this.url);
111
- this.pathname = this.#urlRef.pathname;
35
+ this.pathname = this.req.urlRef.pathname;
112
36
  }
113
37
  header(key, value, options) {
114
38
  let append = options?.append;
@@ -121,16 +45,9 @@ class Context {
121
45
  return this;
122
46
  }
123
47
  get cookies() {
124
- const c = this.#requestHeaders.getAll("cookie");
48
+ const c = this.req.headers.get("cookie");
125
49
  let cookies = {};
126
- if (Array.isArray(c) && c.length != 0) {
127
- const cookieHeader = c.join("; ").split(";");
128
- for (const pair of cookieHeader) {
129
- const [key, value] = pair?.trim()?.split("=");
130
- cookies[key] = decodeURIComponent(value);
131
- }
132
- }
133
- else if (typeof c == "string") {
50
+ if (typeof c == "string") {
134
51
  const cookieHeader = c.split(";");
135
52
  for (const pair of cookieHeader) {
136
53
  const [key, value] = pair?.trim()?.split("=");
@@ -422,9 +339,8 @@ class Context {
422
339
  }
423
340
  get req() {
424
341
  return new request_js_1.Request({
425
- headers: this.#requestHeaders,
426
- req: this.#rawRequest,
427
- urlRef: this.#urlRef,
342
+ method: this.method,
343
+ req: this.rawRequest,
428
344
  options: this.#options,
429
345
  params: this.#params,
430
346
  });
@@ -11,13 +11,5 @@ class EnvironmentDetector {
11
11
  return "node";
12
12
  return "unknown";
13
13
  }
14
- static getHost(headers) {
15
- try {
16
- return headers?.get("host") || "unknown";
17
- }
18
- catch (error) {
19
- throw new Error("Failed to get host.");
20
- }
21
- }
22
14
  }
23
15
  exports.EnvironmentDetector = EnvironmentDetector;
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Request = void 0;
4
4
  const formData_js_1 = require("../utils/formData.js");
5
- const header_js_1 = require("./header.js");
5
+ const url_js_1 = require("../utils/url.js");
6
6
  class Request {
7
- #headers = new header_js_1.HeadersParser();
8
7
  url;
9
8
  method;
10
9
  urlRef = {
@@ -20,25 +19,23 @@ class Request {
20
19
  rawRequest;
21
20
  params = {};
22
21
  remoteAddress = {};
23
- constructor({ headers, params, req, options, urlRef, }) {
22
+ constructor({ params, method, req, options, }) {
23
+ let parse = (0, url_js_1.urlParse)(req.url);
24
+ let url = parse?.href;
24
25
  this.remoteAddress = options?.connInfo?.remoteAddr;
25
- this.#headers = headers;
26
- this.url = urlRef.href || "";
27
- this.urlRef = urlRef;
28
- this.method = req?.method?.toUpperCase();
26
+ this.url = url || "";
27
+ this.urlRef = parse;
28
+ this.method = method;
29
29
  this.params = params;
30
30
  this.rawRequest = req;
31
- this.query = urlRef.query;
31
+ this.query = parse.query;
32
32
  }
33
33
  get headers() {
34
- let requestHeaders = this.#headers;
34
+ let requestHeaders = this.rawRequest.headers;
35
35
  return {
36
36
  get: function get(key) {
37
37
  return requestHeaders.get(key.toLowerCase());
38
38
  },
39
- getAll: function getAll(key) {
40
- return requestHeaders.get(key.toLowerCase()) || [];
41
- },
42
39
  has: function has(key) {
43
40
  return requestHeaders.has(key.toLowerCase());
44
41
  },
@@ -51,47 +48,94 @@ class Request {
51
48
  values: function values() {
52
49
  return requestHeaders.values();
53
50
  },
54
- forEach: function forEach(callback) {
55
- return requestHeaders.forEach(callback);
51
+ forEach: function forEach(callbackfn) {
52
+ return requestHeaders.forEach(callbackfn);
56
53
  },
57
54
  toJSON() {
58
55
  return requestHeaders.toJSON();
59
56
  },
60
- toObject: function toObject() {
61
- return requestHeaders.toObject();
62
- },
63
57
  };
64
58
  }
65
59
  async text() {
66
- return await (0, formData_js_1.parseTextBody)(this.rawRequest);
60
+ return await this.rawRequest.text();
67
61
  }
68
62
  async json() {
69
- const contentType = this.#headers.get("content-type") || "";
63
+ const contentType = this.rawRequest.headers.get("content-type") || "";
70
64
  if (contentType.includes("application/json")) {
71
- return await (0, formData_js_1.parseJsonBody)(this.rawRequest);
65
+ return await this.rawRequest.json();
72
66
  }
73
67
  else {
74
68
  return {};
75
69
  }
76
70
  }
77
71
  async formData(options) {
78
- const contentType = this.#headers.get("content-type") || "";
72
+ const contentType = this.rawRequest.headers.get("content-type") || "";
79
73
  if (!contentType) {
80
74
  throw Error("Invalid Content-Type");
81
75
  }
82
76
  if (contentType.includes("application/json")) {
83
- return await (0, formData_js_1.parseJsonBody)(this.rawRequest);
77
+ return await this.rawRequest.json();
84
78
  }
85
79
  else if (contentType.includes("application/x-www-form-urlencoded")) {
86
- return (0, formData_js_1.parseUrlEncodedBody)(this.rawRequest);
80
+ const formData = await this.rawRequest.formData();
81
+ const result = {};
82
+ for (const [key, value] of formData.entries()) {
83
+ result[key] = value;
84
+ }
85
+ return result;
87
86
  }
88
87
  else if (contentType.includes("multipart/form-data")) {
89
88
  const boundaryMatch = contentType.match(/boundary=([^;]+)/);
90
89
  if (!boundaryMatch) {
91
90
  throw new Error("Boundary not found in multipart/form-data");
92
91
  }
93
- const boundary = boundaryMatch[1];
94
- return await (0, formData_js_1.parseMultipartBody)(this.rawRequest, boundary, options);
92
+ const formData = await this.rawRequest.formData();
93
+ const result = {};
94
+ for (const [key, value] of formData.entries()) {
95
+ let val = value;
96
+ if (val instanceof File && typeof options == "object") {
97
+ let filename = val.name;
98
+ if (options?.sanitized) {
99
+ filename = `${Date.now()}-${(0, formData_js_1.sanitized)(filename)}`;
100
+ }
101
+ if (Array.isArray(options?.allowedTypes) &&
102
+ !options.allowedTypes?.includes(val.type)) {
103
+ throw new Error(`Invalid file type: "${val.type}". Allowed types: ${options.allowedTypes.join(", ")}`);
104
+ }
105
+ if (typeof options?.maxSize !== "undefined" &&
106
+ val.size > options.maxSize) {
107
+ throw new Error(`File size exceeds the limit: ${val.size} bytes (Max: ${options.maxSize} bytes)`);
108
+ }
109
+ if (typeof options?.maxFiles != "undefined" && options.maxFiles == 0) {
110
+ throw new Error(`Field "${key}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
111
+ }
112
+ val = new File([await val.arrayBuffer()], filename, {
113
+ type: val.type,
114
+ });
115
+ }
116
+ if (result[key]) {
117
+ if (Array.isArray(result[key])) {
118
+ if (val instanceof File &&
119
+ typeof options?.maxFiles != "undefined" &&
120
+ result[key]?.length >= options.maxFiles) {
121
+ throw new Error(`Field "${key}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
122
+ }
123
+ result[key].push(val);
124
+ }
125
+ else {
126
+ if (val instanceof File &&
127
+ typeof options?.maxFiles != "undefined" &&
128
+ options.maxFiles == 1) {
129
+ throw new Error(`Field "${key}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
130
+ }
131
+ result[key] = [result[key], val];
132
+ }
133
+ }
134
+ else {
135
+ result[key] = val;
136
+ }
137
+ }
138
+ return result;
95
139
  }
96
140
  else {
97
141
  return {};
@@ -63,6 +63,11 @@ class Router extends MiddlewareConfigure_js_1.default {
63
63
  this.#registerRoute("GET", path, ...args);
64
64
  return this;
65
65
  }
66
+ sse(path, handler) {
67
+ this.get(path, async (ctx) => {
68
+ return handler(ctx);
69
+ });
70
+ }
66
71
  post(path, ...args) {
67
72
  this.#registerRoute("POST", path, ...args);
68
73
  return this;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TezX = void 0;
4
4
  const colors_js_1 = require("../utils/colors.js");
5
+ const httpStatusMap_js_1 = require("../utils/httpStatusMap.js");
5
6
  const params_js_1 = require("../utils/params.js");
6
7
  const config_js_1 = require("./config.js");
7
8
  const context_js_1 = require("./context.js");
@@ -197,12 +198,12 @@ class TezX extends router_js_1.Router {
197
198
  }
198
199
  let finalResponse = () => {
199
200
  return (ctx) => {
200
- if (response?.headers) {
201
- ctx.headers.add(response.headers);
201
+ for (const [key, value] of response?.headers.entries()) {
202
+ ctx.headers.set(key, value);
202
203
  }
203
- const statusText = response?.statusText || context_js_1.httpStatusMap[response?.status] || "";
204
+ const statusText = response?.statusText || httpStatusMap_js_1.httpStatusMap[response?.status] || "";
204
205
  const status = response.status || ctx.getStatus;
205
- let headers = ctx.headers.toObject();
206
+ let headers = ctx.headers.toJSON();
206
207
  return new Response(response.body, {
207
208
  status,
208
209
  statusText,
@@ -221,7 +222,7 @@ class TezX extends router_js_1.Router {
221
222
  if (err instanceof Error) {
222
223
  error = err.stack;
223
224
  }
224
- config_js_1.GlobalConfig.debugging.error(`${colors_js_1.COLORS.bgRed} ${ctx.pathname}, Method: ${ctx.method} ${colors_js_1.COLORS.reset}`, `${context_js_1.httpStatusMap[500]}: ${error} `);
225
+ config_js_1.GlobalConfig.debugging.error(`${colors_js_1.COLORS.bgRed} ${ctx.pathname}, Method: ${ctx.method} ${colors_js_1.COLORS.reset}`, `${httpStatusMap_js_1.httpStatusMap[500]}: ${error} `);
225
226
  let res = await config_js_1.GlobalConfig.onError(error, ctx);
226
227
  ctx.setStatus = res.status;
227
228
  return res;
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.73";
10
+ exports.version = "1.0.75-beta";
@@ -15,7 +15,7 @@ const basicAuth = (options) => {
15
15
  if (rateLimit && !rateLimit.storage) {
16
16
  storage = (0, detectBot_js_1.createRateLimitDefaultStorage)();
17
17
  }
18
- return async (ctx, next) => {
18
+ return async function basicAuth(ctx, next) {
19
19
  let authMethod;
20
20
  let credentials = {};
21
21
  const authHeader = ctx.req.headers.get("authorization");
@@ -11,7 +11,7 @@ const cacheControl = (options) => {
11
11
  config_js_1.GlobalConfig.debugging.success(`[CACHE] ${event.toUpperCase()} for ${ctx.method} ${ctx.pathname}`);
12
12
  }
13
13
  }, } = options;
14
- return async (ctx, next) => {
14
+ return async function cacheControl(ctx, next) {
15
15
  if (!["GET", "HEAD"].includes(ctx.method)) {
16
16
  return await next();
17
17
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cors = cors;
4
4
  function cors(option = {}) {
5
5
  const { methods, allowedHeaders, credentials, exposedHeaders, maxAge, origin, } = option;
6
- return async (ctx, next) => {
6
+ return async function cors(ctx, next) {
7
7
  const reqOrigin = ctx.req.headers.get("origin") || "";
8
8
  let allowOrigin = "*";
9
9
  if (typeof origin === "string") {
@@ -41,7 +41,7 @@ function cors(option = {}) {
41
41
  if (ctx.req.method === "OPTIONS") {
42
42
  return new Response(null, {
43
43
  status: 204,
44
- headers: ctx.headers.toObject(),
44
+ headers: ctx.headers.toJSON(),
45
45
  });
46
46
  }
47
47
  return await next();
@@ -13,7 +13,7 @@ const detectBot = (options = {}) => {
13
13
  if (enableRateLimiting) {
14
14
  store = createRateLimitDefaultStorage();
15
15
  }
16
- return async (ctx, next) => {
16
+ return async function detectBot(ctx, next) {
17
17
  const detectionResult = {
18
18
  isBot: false,
19
19
  indicators: [],
@@ -4,7 +4,7 @@ exports.detectLocale = void 0;
4
4
  const config_js_1 = require("../core/config.js");
5
5
  const detectLocale = (options) => {
6
6
  const { supportedLocales, defaultLocale = "en", queryKeyLocale = "lang", cookieKeyLocale = "locale", localeContextKey = "locale", customLocaleDetector, } = options;
7
- return async (ctx, next) => {
7
+ return async function detectLocale(ctx, next) {
8
8
  let detectedLocale;
9
9
  const queryLocale = ctx.req.query[queryKeyLocale];
10
10
  if (queryLocale && supportedLocales.includes(queryLocale)) {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.i18nMiddleware = void 0;
3
+ exports.i18n = void 0;
4
4
  const config_js_1 = require("../core/config.js");
5
- const i18nMiddleware = (options) => {
5
+ const i18n = (options) => {
6
6
  const { loadTranslations, defaultCacheDuration = 3600000, isCacheValid = (cached) => cached.expiresAt > Date.now(), detectLanguage = (ctx) => ctx.req.query.lang ||
7
7
  ctx.cookies?.get("lang") ||
8
8
  ctx.req.headers.get("accept-language")?.split(",")[0] ||
@@ -11,7 +11,7 @@ const i18nMiddleware = (options) => {
11
11
  return Object.entries(options).reduce((msg, [key, value]) => msg.replace(new RegExp(`{{${key}}}`, "g"), String(value)), message);
12
12
  }, cacheTranslations = true, } = options;
13
13
  const translationCache = {};
14
- return async (ctx, next) => {
14
+ return async function i18n(ctx, next) {
15
15
  try {
16
16
  const detectedLanguage = detectLanguage(ctx);
17
17
  const languageChain = [
@@ -76,4 +76,4 @@ const i18nMiddleware = (options) => {
76
76
  }
77
77
  };
78
78
  };
79
- exports.i18nMiddleware = i18nMiddleware;
79
+ exports.i18n = i18n;
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "cors", { enumerable: true, get: function () { re
21
21
  var detectBot_js_1 = require("./detectBot.js");
22
22
  Object.defineProperty(exports, "detectBot", { enumerable: true, get: function () { return detectBot_js_1.detectBot; } });
23
23
  __exportStar(require("./detectLocale.js"), exports);
24
- __exportStar(require("./i18nMiddleware.js"), exports);
24
+ __exportStar(require("./i18n.js"), exports);
25
25
  __exportStar(require("./lazyLoadModules.js"), exports);
26
26
  __exportStar(require("./logger.js"), exports);
27
27
  __exportStar(require("./pagination.js"), exports);
@@ -8,7 +8,7 @@ const lazyLoadModules = (options) => {
8
8
  if (enableCache && !cacheStorage) {
9
9
  storage = new Map();
10
10
  }
11
- return async (ctx, next) => {
11
+ return async function lazyLoadModules(ctx, next) {
12
12
  let moduleName = moduleKey(ctx) ||
13
13
  ctx.req.params[queryKeyModule] ||
14
14
  ctx.req.query[queryKeyModule];
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logger = logger;
4
4
  const colors_js_1 = require("../utils/colors.js");
5
5
  function logger() {
6
- return async (ctx, next) => {
6
+ return async function logger(ctx, next) {
7
7
  try {
8
8
  console.log(`${colors_js_1.COLORS.bold}<-- ${colors_js_1.COLORS.reset}${colors_js_1.COLORS.bgMagenta} ${ctx.method} ${colors_js_1.COLORS.reset} ${ctx.pathname}`);
9
9
  const startTime = performance.now();