tezx 3.0.6-beta → 3.0.7-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/context.js +22 -11
- package/cjs/index.js +1 -1
- package/core/context.d.ts +12 -1
- package/core/context.js +22 -11
- package/index.js +1 -1
- package/package.json +1 -1
package/cjs/core/context.js
CHANGED
|
@@ -44,8 +44,9 @@ class Context {
|
|
|
44
44
|
}
|
|
45
45
|
setHeader(key, value, options) {
|
|
46
46
|
let _key = key.toLowerCase();
|
|
47
|
+
let append = options?.append || _key == 'set-cookie';
|
|
47
48
|
if (!this.res) {
|
|
48
|
-
if (
|
|
49
|
+
if (append && this.#headers[_key]) {
|
|
49
50
|
this.#headers[_key] += `, ${value}`;
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
@@ -54,7 +55,7 @@ class Context {
|
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
56
57
|
const resHeaders = this.res.headers;
|
|
57
|
-
if (
|
|
58
|
+
if (append) {
|
|
58
59
|
resHeaders.append(_key, value);
|
|
59
60
|
}
|
|
60
61
|
else {
|
|
@@ -63,6 +64,16 @@ class Context {
|
|
|
63
64
|
}
|
|
64
65
|
return this;
|
|
65
66
|
}
|
|
67
|
+
deleteHeader(key) {
|
|
68
|
+
const _key = key.toLowerCase();
|
|
69
|
+
if (!this.res) {
|
|
70
|
+
delete this.#headers[_key];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.res.headers.delete(_key);
|
|
74
|
+
}
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
66
77
|
get params() {
|
|
67
78
|
return this.#params;
|
|
68
79
|
}
|
|
@@ -85,14 +96,14 @@ class Context {
|
|
|
85
96
|
this.#status = status;
|
|
86
97
|
return this;
|
|
87
98
|
};
|
|
88
|
-
|
|
99
|
+
newResponse(body, init = {}) {
|
|
89
100
|
const headers = { ...this.#headers, ...init.headers };
|
|
90
101
|
const status = init.status || this.#status;
|
|
91
102
|
const statusText = init.statusText;
|
|
92
103
|
return new Response(body, { status, statusText, headers });
|
|
93
104
|
}
|
|
94
105
|
text(content, init) {
|
|
95
|
-
return this.
|
|
106
|
+
return this.newResponse(content, {
|
|
96
107
|
...init,
|
|
97
108
|
headers: {
|
|
98
109
|
"Content-Type": "text/plain; charset=utf-8",
|
|
@@ -107,7 +118,7 @@ class Context {
|
|
|
107
118
|
const value = args?.[i] ?? "";
|
|
108
119
|
return result + str + value;
|
|
109
120
|
}, "");
|
|
110
|
-
return this.
|
|
121
|
+
return this.newResponse(html, {
|
|
111
122
|
headers: {
|
|
112
123
|
"Content-Type": "text/html; charset=utf-8",
|
|
113
124
|
},
|
|
@@ -115,7 +126,7 @@ class Context {
|
|
|
115
126
|
}
|
|
116
127
|
else {
|
|
117
128
|
let init = args?.[0];
|
|
118
|
-
return this.
|
|
129
|
+
return this.newResponse(html, {
|
|
119
130
|
...init,
|
|
120
131
|
headers: {
|
|
121
132
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -125,7 +136,7 @@ class Context {
|
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
138
|
xml(xml, init) {
|
|
128
|
-
return this.
|
|
139
|
+
return this.newResponse(xml, {
|
|
129
140
|
...init,
|
|
130
141
|
headers: {
|
|
131
142
|
"Content-Type": "application/xml; charset=utf-8",
|
|
@@ -134,7 +145,7 @@ class Context {
|
|
|
134
145
|
});
|
|
135
146
|
}
|
|
136
147
|
json(json, init) {
|
|
137
|
-
return this.
|
|
148
|
+
return this.newResponse(JSON.stringify(json), {
|
|
138
149
|
...init,
|
|
139
150
|
headers: {
|
|
140
151
|
"Content-Type": "application/json; charset=utf-8",
|
|
@@ -147,7 +158,7 @@ class Context {
|
|
|
147
158
|
const contentType = init?.headers?.["Content-Type"] ||
|
|
148
159
|
init?.headers?.["content-type"] ||
|
|
149
160
|
type;
|
|
150
|
-
return this.
|
|
161
|
+
return this.newResponse(_body, {
|
|
151
162
|
...init,
|
|
152
163
|
headers: {
|
|
153
164
|
"Content-Type": contentType,
|
|
@@ -165,7 +176,7 @@ class Context {
|
|
|
165
176
|
if (!(await (0, file_js_1.fileExists)(filePath)))
|
|
166
177
|
throw Error("File not found");
|
|
167
178
|
let buf = await (0, file_js_1.getFileBuffer)(filePath);
|
|
168
|
-
return this.
|
|
179
|
+
return this.newResponse(buf, {
|
|
169
180
|
status: 200,
|
|
170
181
|
headers: {
|
|
171
182
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
@@ -189,7 +200,7 @@ class Context {
|
|
|
189
200
|
let filename = init?.filename;
|
|
190
201
|
if (filename)
|
|
191
202
|
headers["Content-Disposition"] = `attachment; filename="${filename}"`;
|
|
192
|
-
return this.
|
|
203
|
+
return this.newResponse(fileStream, {
|
|
193
204
|
status: init?.status || 200,
|
|
194
205
|
statusText: init?.statusText,
|
|
195
206
|
headers,
|
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.7-beta";
|
|
9
9
|
exports.default = {
|
|
10
10
|
Router: router_js_1.Router,
|
|
11
11
|
TezX: server_js_1.TezX,
|
package/core/context.d.ts
CHANGED
|
@@ -91,6 +91,17 @@ export declare class Context<T extends Record<string, any> = {}, Path extends st
|
|
|
91
91
|
setHeader(key: ResHeaderKey, value: string, options?: {
|
|
92
92
|
append?: boolean;
|
|
93
93
|
}): this;
|
|
94
|
+
/**
|
|
95
|
+
* Deletes a response header by key.
|
|
96
|
+
*
|
|
97
|
+
* If the native Response object is not yet available (`this.res` is falsy),
|
|
98
|
+
* it removes the header from the internal headers store.
|
|
99
|
+
* If the native Response object is available, it removes the header directly from the response headers.
|
|
100
|
+
*
|
|
101
|
+
* @param {ResHeaderKey} key - The name of the header to delete (case-insensitive).
|
|
102
|
+
* @returns {this} Returns the current instance for method chaining.
|
|
103
|
+
*/
|
|
104
|
+
deleteHeader(key: ResHeaderKey): this;
|
|
94
105
|
/**
|
|
95
106
|
* Gets the route parameters extracted from the URL.
|
|
96
107
|
*
|
|
@@ -138,7 +149,7 @@ export declare class Context<T extends Record<string, any> = {}, Path extends st
|
|
|
138
149
|
* @returns {HttpBaseResponse} Response object suitable for runtime.
|
|
139
150
|
* @protected
|
|
140
151
|
*/
|
|
141
|
-
|
|
152
|
+
newResponse(body: BodyInit | null, init?: ResponseInit): HttpBaseResponse;
|
|
142
153
|
/**
|
|
143
154
|
* Sends a plain text response.
|
|
144
155
|
*
|
package/core/context.js
CHANGED
|
@@ -41,8 +41,9 @@ export class Context {
|
|
|
41
41
|
}
|
|
42
42
|
setHeader(key, value, options) {
|
|
43
43
|
let _key = key.toLowerCase();
|
|
44
|
+
let append = options?.append || _key == 'set-cookie';
|
|
44
45
|
if (!this.res) {
|
|
45
|
-
if (
|
|
46
|
+
if (append && this.#headers[_key]) {
|
|
46
47
|
this.#headers[_key] += `, ${value}`;
|
|
47
48
|
}
|
|
48
49
|
else {
|
|
@@ -51,7 +52,7 @@ export class Context {
|
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
54
|
const resHeaders = this.res.headers;
|
|
54
|
-
if (
|
|
55
|
+
if (append) {
|
|
55
56
|
resHeaders.append(_key, value);
|
|
56
57
|
}
|
|
57
58
|
else {
|
|
@@ -60,6 +61,16 @@ export class Context {
|
|
|
60
61
|
}
|
|
61
62
|
return this;
|
|
62
63
|
}
|
|
64
|
+
deleteHeader(key) {
|
|
65
|
+
const _key = key.toLowerCase();
|
|
66
|
+
if (!this.res) {
|
|
67
|
+
delete this.#headers[_key];
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.res.headers.delete(_key);
|
|
71
|
+
}
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
63
74
|
get params() {
|
|
64
75
|
return this.#params;
|
|
65
76
|
}
|
|
@@ -82,14 +93,14 @@ export class Context {
|
|
|
82
93
|
this.#status = status;
|
|
83
94
|
return this;
|
|
84
95
|
};
|
|
85
|
-
|
|
96
|
+
newResponse(body, init = {}) {
|
|
86
97
|
const headers = { ...this.#headers, ...init.headers };
|
|
87
98
|
const status = init.status || this.#status;
|
|
88
99
|
const statusText = init.statusText;
|
|
89
100
|
return new Response(body, { status, statusText, headers });
|
|
90
101
|
}
|
|
91
102
|
text(content, init) {
|
|
92
|
-
return this.
|
|
103
|
+
return this.newResponse(content, {
|
|
93
104
|
...init,
|
|
94
105
|
headers: {
|
|
95
106
|
"Content-Type": "text/plain; charset=utf-8",
|
|
@@ -104,7 +115,7 @@ export class Context {
|
|
|
104
115
|
const value = args?.[i] ?? "";
|
|
105
116
|
return result + str + value;
|
|
106
117
|
}, "");
|
|
107
|
-
return this.
|
|
118
|
+
return this.newResponse(html, {
|
|
108
119
|
headers: {
|
|
109
120
|
"Content-Type": "text/html; charset=utf-8",
|
|
110
121
|
},
|
|
@@ -112,7 +123,7 @@ export class Context {
|
|
|
112
123
|
}
|
|
113
124
|
else {
|
|
114
125
|
let init = args?.[0];
|
|
115
|
-
return this.
|
|
126
|
+
return this.newResponse(html, {
|
|
116
127
|
...init,
|
|
117
128
|
headers: {
|
|
118
129
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -122,7 +133,7 @@ export class Context {
|
|
|
122
133
|
}
|
|
123
134
|
}
|
|
124
135
|
xml(xml, init) {
|
|
125
|
-
return this.
|
|
136
|
+
return this.newResponse(xml, {
|
|
126
137
|
...init,
|
|
127
138
|
headers: {
|
|
128
139
|
"Content-Type": "application/xml; charset=utf-8",
|
|
@@ -131,7 +142,7 @@ export class Context {
|
|
|
131
142
|
});
|
|
132
143
|
}
|
|
133
144
|
json(json, init) {
|
|
134
|
-
return this.
|
|
145
|
+
return this.newResponse(JSON.stringify(json), {
|
|
135
146
|
...init,
|
|
136
147
|
headers: {
|
|
137
148
|
"Content-Type": "application/json; charset=utf-8",
|
|
@@ -144,7 +155,7 @@ export class Context {
|
|
|
144
155
|
const contentType = init?.headers?.["Content-Type"] ||
|
|
145
156
|
init?.headers?.["content-type"] ||
|
|
146
157
|
type;
|
|
147
|
-
return this.
|
|
158
|
+
return this.newResponse(_body, {
|
|
148
159
|
...init,
|
|
149
160
|
headers: {
|
|
150
161
|
"Content-Type": contentType,
|
|
@@ -162,7 +173,7 @@ export class Context {
|
|
|
162
173
|
if (!(await fileExists(filePath)))
|
|
163
174
|
throw Error("File not found");
|
|
164
175
|
let buf = await getFileBuffer(filePath);
|
|
165
|
-
return this.
|
|
176
|
+
return this.newResponse(buf, {
|
|
166
177
|
status: 200,
|
|
167
178
|
headers: {
|
|
168
179
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
@@ -186,7 +197,7 @@ export class Context {
|
|
|
186
197
|
let filename = init?.filename;
|
|
187
198
|
if (filename)
|
|
188
199
|
headers["Content-Disposition"] = `attachment; filename="${filename}"`;
|
|
189
|
-
return this.
|
|
200
|
+
return this.newResponse(fileStream, {
|
|
190
201
|
status: init?.status || 200,
|
|
191
202
|
statusText: init?.statusText,
|
|
192
203
|
headers,
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7-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",
|