tezx 1.0.66 → 1.0.68
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/server.js +24 -16
- package/cjs/index.js +1 -1
- package/cjs/middleware/requestTimeout.js +2 -2
- package/core/router.d.ts +0 -9
- package/core/server.js +24 -16
- package/index.js +1 -1
- package/middleware/requestTimeout.d.ts +2 -2
- package/middleware/requestTimeout.js +1 -1
- package/package.json +1 -1
package/cjs/core/server.js
CHANGED
|
@@ -78,31 +78,39 @@ class TezX extends router_js_1.Router {
|
|
|
78
78
|
}
|
|
79
79
|
#createHandler(middlewares) {
|
|
80
80
|
return async (ctx) => {
|
|
81
|
-
let response = undefined;
|
|
82
81
|
let index = 0;
|
|
83
|
-
let
|
|
82
|
+
let response = undefined;
|
|
83
|
+
const next = async () => {
|
|
84
|
+
if (index >= middlewares.length) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
84
87
|
const currentMiddleware = middlewares[index++];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
try {
|
|
89
|
+
const result = await currentMiddleware(ctx, next);
|
|
90
|
+
if (result instanceof Response) {
|
|
91
|
+
ctx.res = result;
|
|
92
|
+
}
|
|
93
|
+
if (result !== undefined) {
|
|
94
|
+
response = result;
|
|
95
|
+
}
|
|
96
|
+
return response;
|
|
89
97
|
}
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
catch (err) {
|
|
99
|
+
ctx.body = err;
|
|
100
|
+
throw err;
|
|
92
101
|
}
|
|
93
|
-
return ctx.res;
|
|
94
102
|
};
|
|
95
|
-
await next();
|
|
96
|
-
if (
|
|
97
|
-
return
|
|
103
|
+
let res = await next();
|
|
104
|
+
if (res instanceof Response) {
|
|
105
|
+
return res;
|
|
98
106
|
}
|
|
99
|
-
if (typeof
|
|
100
|
-
return
|
|
107
|
+
if (typeof res == "function" && ctx.wsProtocol) {
|
|
108
|
+
return res;
|
|
101
109
|
}
|
|
102
|
-
if (!
|
|
110
|
+
if (!res && !ctx.body) {
|
|
103
111
|
throw new Error(`Handler failed: Middleware chain incomplete or response missing. Did you forget ${colors_js_1.COLORS.bgRed} 'await next()' ${colors_js_1.COLORS.reset} or to return a response? ${colors_js_1.COLORS.bgCyan} Path: ${ctx.pathname}, Method: ${ctx.method} ${colors_js_1.COLORS.reset}`);
|
|
104
112
|
}
|
|
105
|
-
const resBody =
|
|
113
|
+
const resBody = res || ctx.body;
|
|
106
114
|
return ctx.send(resBody, ctx.headers.toJSON());
|
|
107
115
|
};
|
|
108
116
|
}
|
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.
|
|
10
|
+
exports.version = "1.0.68";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requestTimeout = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_js_1 = require("../core/config.js");
|
|
5
5
|
const requestTimeout = (options) => {
|
|
6
6
|
const { getTimeout, onTimeout = (ctx) => {
|
|
7
7
|
ctx.setStatus = 504;
|
|
8
8
|
ctx.body = { error: "Request timed out." };
|
|
9
9
|
}, logTimeoutEvent = (ctx, error) => {
|
|
10
|
-
|
|
10
|
+
config_js_1.GlobalConfig.debugging.warn(`[TIMEOUT] ${error.message}: ${ctx.method} ${ctx.path}`);
|
|
11
11
|
}, cleanup = () => {
|
|
12
12
|
}, } = options;
|
|
13
13
|
return async (ctx, next) => {
|
package/core/router.d.ts
CHANGED
|
@@ -76,7 +76,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
76
76
|
* app.get('/admin', [authMiddleware, adminMiddleware], (ctx) => { ... });
|
|
77
77
|
*/
|
|
78
78
|
get(path: string, callback: Callback<T>): this;
|
|
79
|
-
get(path: string, middleware: Middleware<T>): this;
|
|
80
79
|
get(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
81
80
|
get(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
82
81
|
/**
|
|
@@ -85,7 +84,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
85
84
|
* @param args - Handler callback or middleware(s) + handler
|
|
86
85
|
*/
|
|
87
86
|
post(path: string, callback: Callback<T>): this;
|
|
88
|
-
post(path: string, middleware: Middleware<T>): this;
|
|
89
87
|
post(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
90
88
|
post(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
91
89
|
/**
|
|
@@ -94,7 +92,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
94
92
|
* @param args - Handler callback or middleware(s) + handler
|
|
95
93
|
*/
|
|
96
94
|
put(path: string, callback: Callback<T>): this;
|
|
97
|
-
put(path: string, middleware: Middleware<T>): this;
|
|
98
95
|
put(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
99
96
|
put(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
100
97
|
/**
|
|
@@ -103,7 +100,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
103
100
|
* @param args - Handler callback or middleware(s) + handler
|
|
104
101
|
*/
|
|
105
102
|
patch(path: string, callback: Callback<T>): this;
|
|
106
|
-
patch(path: string, middleware: Middleware<T>): this;
|
|
107
103
|
patch(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
108
104
|
patch(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
109
105
|
/**
|
|
@@ -112,7 +108,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
112
108
|
* @param args - Handler callback or middleware(s) + handler
|
|
113
109
|
*/
|
|
114
110
|
delete(path: string, callback: Callback<T>): this;
|
|
115
|
-
delete(path: string, middleware: Middleware<T>): this;
|
|
116
111
|
delete(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
117
112
|
delete(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
118
113
|
/**
|
|
@@ -121,7 +116,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
121
116
|
* @param args - Handler callback or middleware(s) + handler
|
|
122
117
|
*/
|
|
123
118
|
options(path: string, callback: Callback<T>): this;
|
|
124
|
-
options(path: string, middleware: Middleware<T>): this;
|
|
125
119
|
options(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
126
120
|
options(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
127
121
|
/**
|
|
@@ -130,7 +124,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
130
124
|
* @param args - Handler callback or middleware(s) + handler
|
|
131
125
|
*/
|
|
132
126
|
head(path: string, callback: Callback<T>): this;
|
|
133
|
-
head(path: string, middleware: Middleware<T>): this;
|
|
134
127
|
head(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
135
128
|
head(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
136
129
|
/**
|
|
@@ -139,7 +132,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
139
132
|
* @param args - Handler callback or middleware(s) + handler
|
|
140
133
|
*/
|
|
141
134
|
all(path: string, callback: Callback<T>): this;
|
|
142
|
-
all(path: string, middleware: Middleware<T>): this;
|
|
143
135
|
all(path: string, middleware: Middleware<T>, callback: Callback<T>): this;
|
|
144
136
|
all(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
145
137
|
/**
|
|
@@ -190,7 +182,6 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
190
182
|
use(path: string, middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
191
183
|
use(path: string, middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
192
184
|
use(path: string, middlewares: Middleware<T>[]): this;
|
|
193
|
-
use(path: string, middleware: Middleware<T>): this;
|
|
194
185
|
use(path: string, callback: Callback<T> | Router<T | any>): this;
|
|
195
186
|
use(middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
196
187
|
use(middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
package/core/server.js
CHANGED
|
@@ -75,31 +75,39 @@ export class TezX extends Router {
|
|
|
75
75
|
}
|
|
76
76
|
#createHandler(middlewares) {
|
|
77
77
|
return async (ctx) => {
|
|
78
|
-
let response = undefined;
|
|
79
78
|
let index = 0;
|
|
80
|
-
let
|
|
79
|
+
let response = undefined;
|
|
80
|
+
const next = async () => {
|
|
81
|
+
if (index >= middlewares.length) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
81
84
|
const currentMiddleware = middlewares[index++];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
try {
|
|
86
|
+
const result = await currentMiddleware(ctx, next);
|
|
87
|
+
if (result instanceof Response) {
|
|
88
|
+
ctx.res = result;
|
|
89
|
+
}
|
|
90
|
+
if (result !== undefined) {
|
|
91
|
+
response = result;
|
|
92
|
+
}
|
|
93
|
+
return response;
|
|
86
94
|
}
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
catch (err) {
|
|
96
|
+
ctx.body = err;
|
|
97
|
+
throw err;
|
|
89
98
|
}
|
|
90
|
-
return ctx.res;
|
|
91
99
|
};
|
|
92
|
-
await next();
|
|
93
|
-
if (
|
|
94
|
-
return
|
|
100
|
+
let res = await next();
|
|
101
|
+
if (res instanceof Response) {
|
|
102
|
+
return res;
|
|
95
103
|
}
|
|
96
|
-
if (typeof
|
|
97
|
-
return
|
|
104
|
+
if (typeof res == "function" && ctx.wsProtocol) {
|
|
105
|
+
return res;
|
|
98
106
|
}
|
|
99
|
-
if (!
|
|
107
|
+
if (!res && !ctx.body) {
|
|
100
108
|
throw new Error(`Handler failed: Middleware chain incomplete or response missing. Did you forget ${COLORS.bgRed} 'await next()' ${COLORS.reset} or to return a response? ${COLORS.bgCyan} Path: ${ctx.pathname}, Method: ${ctx.method} ${COLORS.reset}`);
|
|
101
109
|
}
|
|
102
|
-
const resBody =
|
|
110
|
+
const resBody = res || ctx.body;
|
|
103
111
|
return ctx.send(resBody, ctx.headers.toJSON());
|
|
104
112
|
};
|
|
105
113
|
}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Context } from "../core/context";
|
|
2
|
-
import { CallbackReturn, Middleware } from "../core/router";
|
|
1
|
+
import { Context } from "../core/context.js";
|
|
2
|
+
import { CallbackReturn, Middleware } from "../core/router.js";
|
|
3
3
|
type TimeoutOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* ⏳ Function to dynamically determine the timeout duration (in milliseconds).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.68",
|
|
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",
|