srvx 0.8.4 → 0.8.6
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/README.md +3 -0
- package/dist/_chunks/_utils.cli-B2YzwlOv.mjs +31 -0
- package/dist/_chunks/call-CKpEER8U.mjs +43 -0
- package/dist/_chunks/response-Ca-wGejU.mjs +358 -0
- package/dist/_chunks/{types-GwbH0R0m.d.mts → types-BXtbU5Z8.d.mts} +2 -1
- package/dist/adapters/bun.d.mts +2 -2
- package/dist/adapters/cloudflare.d.mts +1 -1
- package/dist/adapters/cloudflare.mjs +1 -1
- package/dist/adapters/deno.d.mts +2 -2
- package/dist/adapters/generic.d.mts +1 -1
- package/dist/adapters/generic.mjs +1 -1
- package/dist/adapters/node.d.mts +3 -3
- package/dist/adapters/node.mjs +2 -356
- package/dist/adapters/service-worker.d.mts +1 -1
- package/dist/adapters/service-worker.mjs +1 -1
- package/dist/cli.d.mts +7 -0
- package/dist/cli.mjs +130 -49
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +8 -2
- package/dist/static.d.mts +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +13 -13
- package/dist/_chunks/_utils.cli-4eOGyiAa.mjs +0 -17
- package/dist/_chunks/package-CN4H7C-a.mjs +0 -104
- /package/dist/_chunks/{_plugins-CbGQstxC.mjs → _plugins-DOhVIkXu.mjs} +0 -0
- /package/dist/_chunks/{_url-Bu46KnwC.d.mts → _url-D8u5OAto.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -52,9 +52,12 @@ $ bunx --bun srvx
|
|
|
52
52
|
| Example | Source | Try |
|
|
53
53
|
| ---------------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
|
|
54
54
|
| `elysia` | [examples/elysia](https://github.com/h3js/srvx/tree/main/examples/elysia/) | `npx giget gh:h3js/srvx/examples/elysia srvx-elysia` |
|
|
55
|
+
| `express` | [examples/express](https://github.com/h3js/srvx/tree/main/examples/express/) | `npx giget gh:h3js/srvx/examples/express srvx-express` |
|
|
55
56
|
| `h3` | [examples/h3](https://github.com/h3js/srvx/tree/main/examples/h3/) | `npx giget gh:h3js/srvx/examples/h3 srvx-h3` |
|
|
56
57
|
| `hello-world` | [examples/hello-world](https://github.com/h3js/srvx/tree/main/examples/hello-world/) | `npx giget gh:h3js/srvx/examples/hello-world srvx-hello-world` |
|
|
57
58
|
| `hono` | [examples/hono](https://github.com/h3js/srvx/tree/main/examples/hono/) | `npx giget gh:h3js/srvx/examples/hono srvx-hono` |
|
|
59
|
+
| `jsx` | [examples/jsx](https://github.com/h3js/srvx/tree/main/examples/jsx/) | `npx giget gh:h3js/srvx/examples/jsx srvx-jsx` |
|
|
60
|
+
| `node-handler` | [examples/node-handler](https://github.com/h3js/srvx/tree/main/examples/node-handler/) | `npx giget gh:h3js/srvx/examples/node-handler srvx-node-handler` |
|
|
58
61
|
| `service-worker` | [examples/service-worker](https://github.com/h3js/srvx/tree/main/examples/service-worker/) | `npx giget gh:h3js/srvx/examples/service-worker srvx-service-worker` |
|
|
59
62
|
| `websocket` | [examples/websocket](https://github.com/h3js/srvx/tree/main/examples/websocket/) | `npx giget gh:h3js/srvx/examples/websocket srvx-websocket` |
|
|
60
63
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/_utils.cli.ts
|
|
2
|
+
const noColor = globalThis.process?.env?.NO_COLOR === "1" || globalThis.process?.env?.TERM === "dumb";
|
|
3
|
+
const resets = {
|
|
4
|
+
1: 22,
|
|
5
|
+
31: 39,
|
|
6
|
+
32: 39,
|
|
7
|
+
33: 39,
|
|
8
|
+
34: 39,
|
|
9
|
+
35: 39,
|
|
10
|
+
36: 39,
|
|
11
|
+
90: 39
|
|
12
|
+
};
|
|
13
|
+
const _c = (c) => (text) => {
|
|
14
|
+
if (noColor) return text;
|
|
15
|
+
const off = resets[c] ?? 0;
|
|
16
|
+
return `\u001B[${c}m${text}\u001B[${off}m`;
|
|
17
|
+
};
|
|
18
|
+
const Colors = {
|
|
19
|
+
bold: _c(1),
|
|
20
|
+
red: _c(31),
|
|
21
|
+
green: _c(32),
|
|
22
|
+
yellow: _c(33),
|
|
23
|
+
blue: _c(34),
|
|
24
|
+
magenta: _c(35),
|
|
25
|
+
cyan: _c(36),
|
|
26
|
+
gray: _c(90),
|
|
27
|
+
url: (title, url) => noColor ? `[${title}](${url})` : `\u001B]8;;${url}\u001B\\${title}\u001B]8;;\u001B\\`
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Colors };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NodeResponse, NodeResponseHeaders } from "./response-Ca-wGejU.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/_node/call.ts
|
|
4
|
+
function callNodeHandler(handler, req) {
|
|
5
|
+
const isMiddleware = handler.length > 2;
|
|
6
|
+
const nodeCtx = req.runtime?.node;
|
|
7
|
+
if (!nodeCtx || !nodeCtx.req || !nodeCtx.res) throw new Error("Node.js runtime context is not available.");
|
|
8
|
+
const { req: nodeReq, res: nodeRes } = nodeCtx;
|
|
9
|
+
let _headers;
|
|
10
|
+
const webRes = new NodeResponse(void 0, {
|
|
11
|
+
get status() {
|
|
12
|
+
return nodeRes.statusCode;
|
|
13
|
+
},
|
|
14
|
+
get statusText() {
|
|
15
|
+
return nodeRes.statusMessage;
|
|
16
|
+
},
|
|
17
|
+
get headers() {
|
|
18
|
+
if (!_headers) _headers = new NodeResponseHeaders(nodeCtx);
|
|
19
|
+
return _headers;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
nodeRes.once("close", () => resolve(webRes));
|
|
24
|
+
nodeRes.once("finish", () => resolve(webRes));
|
|
25
|
+
nodeRes.once("error", (error) => reject(error));
|
|
26
|
+
let streamPromise;
|
|
27
|
+
nodeRes.once("pipe", (stream) => {
|
|
28
|
+
streamPromise = new Promise((resolve$1) => {
|
|
29
|
+
stream.once("end", () => resolve$1(webRes));
|
|
30
|
+
stream.once("error", (error) => reject(error));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
if (isMiddleware) Promise.resolve(handler(nodeReq, nodeRes, (error) => error ? reject(error) : streamPromise || resolve(webRes))).catch((error) => reject(error));
|
|
35
|
+
else Promise.resolve(handler(nodeReq, nodeRes)).then(() => streamPromise || webRes);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
reject(error);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { callNodeHandler };
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { splitSetCookieString } from "cookie-es";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/_node/_common.ts
|
|
4
|
+
const kNodeInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/adapters/_node/headers.ts
|
|
8
|
+
const NodeRequestHeaders = /* @__PURE__ */ (() => {
|
|
9
|
+
const _Headers = class Headers$1 {
|
|
10
|
+
_node;
|
|
11
|
+
constructor(nodeCtx) {
|
|
12
|
+
this._node = nodeCtx;
|
|
13
|
+
}
|
|
14
|
+
append(name, value) {
|
|
15
|
+
name = validateHeader(name);
|
|
16
|
+
const _headers = this._node.req.headers;
|
|
17
|
+
const _current = _headers[name];
|
|
18
|
+
if (_current) if (Array.isArray(_current)) _current.push(value);
|
|
19
|
+
else _headers[name] = [_current, value];
|
|
20
|
+
else _headers[name] = value;
|
|
21
|
+
}
|
|
22
|
+
delete(name) {
|
|
23
|
+
name = validateHeader(name);
|
|
24
|
+
this._node.req.headers[name] = void 0;
|
|
25
|
+
}
|
|
26
|
+
get(name) {
|
|
27
|
+
name = validateHeader(name);
|
|
28
|
+
const rawValue = this._node.req.headers[name];
|
|
29
|
+
if (rawValue === void 0) return null;
|
|
30
|
+
return _normalizeValue(this._node.req.headers[name]);
|
|
31
|
+
}
|
|
32
|
+
getSetCookie() {
|
|
33
|
+
const setCookie = this._node.req.headers["set-cookie"];
|
|
34
|
+
if (!setCookie || setCookie.length === 0) return [];
|
|
35
|
+
return splitSetCookieString(setCookie);
|
|
36
|
+
}
|
|
37
|
+
has(name) {
|
|
38
|
+
name = validateHeader(name);
|
|
39
|
+
return !!this._node.req.headers[name];
|
|
40
|
+
}
|
|
41
|
+
set(name, value) {
|
|
42
|
+
name = validateHeader(name);
|
|
43
|
+
this._node.req.headers[name] = value;
|
|
44
|
+
}
|
|
45
|
+
get count() {
|
|
46
|
+
throw new Error("Method not implemented.");
|
|
47
|
+
}
|
|
48
|
+
getAll(_name) {
|
|
49
|
+
throw new Error("Method not implemented.");
|
|
50
|
+
}
|
|
51
|
+
toJSON() {
|
|
52
|
+
const _headers = this._node.req.headers;
|
|
53
|
+
const result = {};
|
|
54
|
+
for (const key in _headers) if (_headers[key]) result[key] = _normalizeValue(_headers[key]);
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
forEach(cb, thisArg) {
|
|
58
|
+
const _headers = this._node.req.headers;
|
|
59
|
+
for (const key in _headers) if (_headers[key]) cb.call(thisArg, _normalizeValue(_headers[key]), key, this);
|
|
60
|
+
}
|
|
61
|
+
*entries() {
|
|
62
|
+
const headers = this._node.req.headers;
|
|
63
|
+
const isHttp2 = this._node.req.httpVersion === "2.0";
|
|
64
|
+
for (const key in headers) if (!isHttp2 || key[0] !== ":") yield [key, _normalizeValue(headers[key])];
|
|
65
|
+
}
|
|
66
|
+
*keys() {
|
|
67
|
+
const keys = Object.keys(this._node.req.headers);
|
|
68
|
+
for (const key of keys) yield key;
|
|
69
|
+
}
|
|
70
|
+
*values() {
|
|
71
|
+
const values = Object.values(this._node.req.headers);
|
|
72
|
+
for (const value of values) yield _normalizeValue(value);
|
|
73
|
+
}
|
|
74
|
+
[Symbol.iterator]() {
|
|
75
|
+
return this.entries()[Symbol.iterator]();
|
|
76
|
+
}
|
|
77
|
+
get [Symbol.toStringTag]() {
|
|
78
|
+
return "Headers";
|
|
79
|
+
}
|
|
80
|
+
[kNodeInspect]() {
|
|
81
|
+
return Object.fromEntries(this.entries());
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
Object.setPrototypeOf(_Headers.prototype, globalThis.Headers.prototype);
|
|
85
|
+
return _Headers;
|
|
86
|
+
})();
|
|
87
|
+
const NodeResponseHeaders = /* @__PURE__ */ (() => {
|
|
88
|
+
const _Headers = class Headers$1 {
|
|
89
|
+
_node;
|
|
90
|
+
constructor(nodeCtx) {
|
|
91
|
+
this._node = nodeCtx;
|
|
92
|
+
}
|
|
93
|
+
append(name, value) {
|
|
94
|
+
this._node.res.appendHeader(name, value);
|
|
95
|
+
}
|
|
96
|
+
delete(name) {
|
|
97
|
+
this._node.res.removeHeader(name);
|
|
98
|
+
}
|
|
99
|
+
get(name) {
|
|
100
|
+
const rawValue = this._node.res.getHeader(name);
|
|
101
|
+
if (rawValue === void 0) return null;
|
|
102
|
+
return _normalizeValue(rawValue);
|
|
103
|
+
}
|
|
104
|
+
getSetCookie() {
|
|
105
|
+
const setCookie = _normalizeValue(this._node.res.getHeader("set-cookie"));
|
|
106
|
+
if (!setCookie) return [];
|
|
107
|
+
return splitSetCookieString(setCookie);
|
|
108
|
+
}
|
|
109
|
+
has(name) {
|
|
110
|
+
return this._node.res.hasHeader(name);
|
|
111
|
+
}
|
|
112
|
+
set(name, value) {
|
|
113
|
+
this._node.res.setHeader(name, value);
|
|
114
|
+
}
|
|
115
|
+
get count() {
|
|
116
|
+
throw new Error("Method not implemented.");
|
|
117
|
+
}
|
|
118
|
+
getAll(_name) {
|
|
119
|
+
throw new Error("Method not implemented.");
|
|
120
|
+
}
|
|
121
|
+
toJSON() {
|
|
122
|
+
const _headers = this._node.res.getHeaders();
|
|
123
|
+
const result = {};
|
|
124
|
+
for (const key in _headers) if (_headers[key]) result[key] = _normalizeValue(_headers[key]);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
forEach(cb, thisArg) {
|
|
128
|
+
const _headers = this._node.res.getHeaders();
|
|
129
|
+
for (const key in _headers) if (_headers[key]) cb.call(thisArg, _normalizeValue(_headers[key]), key, this);
|
|
130
|
+
}
|
|
131
|
+
*entries() {
|
|
132
|
+
const _headers = this._node.res.getHeaders();
|
|
133
|
+
for (const key in _headers) yield [key, _normalizeValue(_headers[key])];
|
|
134
|
+
}
|
|
135
|
+
*keys() {
|
|
136
|
+
const keys = this._node.res.getHeaderNames();
|
|
137
|
+
for (const key of keys) yield key;
|
|
138
|
+
}
|
|
139
|
+
*values() {
|
|
140
|
+
const values = Object.values(this._node.res.getHeaders());
|
|
141
|
+
for (const value of values) yield _normalizeValue(value);
|
|
142
|
+
}
|
|
143
|
+
[Symbol.iterator]() {
|
|
144
|
+
return this.entries()[Symbol.iterator]();
|
|
145
|
+
}
|
|
146
|
+
get [Symbol.toStringTag]() {
|
|
147
|
+
return "Headers";
|
|
148
|
+
}
|
|
149
|
+
[kNodeInspect]() {
|
|
150
|
+
return Object.fromEntries(this.entries());
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
Object.setPrototypeOf(_Headers.prototype, globalThis.Headers.prototype);
|
|
154
|
+
return _Headers;
|
|
155
|
+
})();
|
|
156
|
+
function _normalizeValue(value) {
|
|
157
|
+
if (Array.isArray(value)) return value.join(", ");
|
|
158
|
+
return typeof value === "string" ? value : String(value ?? "");
|
|
159
|
+
}
|
|
160
|
+
function validateHeader(name) {
|
|
161
|
+
if (name[0] === ":") throw new TypeError(`${JSON.stringify(name)} is an invalid header name.`);
|
|
162
|
+
return name.toLowerCase();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/adapters/_node/response.ts
|
|
167
|
+
/**
|
|
168
|
+
* Fast Response for Node.js runtime
|
|
169
|
+
*
|
|
170
|
+
* It is faster because in most cases it doesn't create a full Response instance.
|
|
171
|
+
*/
|
|
172
|
+
const NodeResponse = /* @__PURE__ */ (() => {
|
|
173
|
+
const CONTENT_TYPE = "content-type";
|
|
174
|
+
const JSON_TYPE = "application/json";
|
|
175
|
+
const JSON_HEADER = [[CONTENT_TYPE, JSON_TYPE]];
|
|
176
|
+
const _Response = class Response {
|
|
177
|
+
#body;
|
|
178
|
+
#init;
|
|
179
|
+
constructor(body, init) {
|
|
180
|
+
this.#body = body;
|
|
181
|
+
this.#init = init;
|
|
182
|
+
}
|
|
183
|
+
static json(data, init) {
|
|
184
|
+
if (init?.headers) {
|
|
185
|
+
if (!init.headers[CONTENT_TYPE]) {
|
|
186
|
+
const initHeaders = new Headers(init.headers);
|
|
187
|
+
if (!initHeaders.has(CONTENT_TYPE)) initHeaders.set(CONTENT_TYPE, JSON_TYPE);
|
|
188
|
+
init = {
|
|
189
|
+
...init,
|
|
190
|
+
headers: initHeaders
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
init = init ? { ...init } : {};
|
|
195
|
+
init.headers = JSON_HEADER;
|
|
196
|
+
}
|
|
197
|
+
return new _Response(JSON.stringify(data), init);
|
|
198
|
+
}
|
|
199
|
+
static error() {
|
|
200
|
+
return globalThis.Response.error();
|
|
201
|
+
}
|
|
202
|
+
static redirect(url, status) {
|
|
203
|
+
return globalThis.Response.redirect(url, status);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Prepare Node.js response object
|
|
207
|
+
*/
|
|
208
|
+
nodeResponse() {
|
|
209
|
+
const status = this.#init?.status ?? 200;
|
|
210
|
+
const statusText = this.#init?.statusText ?? "";
|
|
211
|
+
const headers = [];
|
|
212
|
+
const headersInit = this.#init?.headers;
|
|
213
|
+
if (this.#headersObj) for (const [key, value] of this.#headersObj) if (key === "set-cookie") for (const setCookie of splitSetCookieString(value)) headers.push(["set-cookie", setCookie]);
|
|
214
|
+
else headers.push([key, value]);
|
|
215
|
+
else if (headersInit) {
|
|
216
|
+
const headerEntries = Array.isArray(headersInit) ? headersInit : headersInit.entries ? headersInit.entries() : Object.entries(headersInit);
|
|
217
|
+
for (const [key, value] of headerEntries) if (key === "set-cookie") for (const setCookie of splitSetCookieString(value)) headers.push(["set-cookie", setCookie]);
|
|
218
|
+
else headers.push([key, value]);
|
|
219
|
+
}
|
|
220
|
+
const bodyInit = this.#body;
|
|
221
|
+
let body;
|
|
222
|
+
if (bodyInit) if (typeof bodyInit === "string") body = bodyInit;
|
|
223
|
+
else if (bodyInit instanceof ReadableStream) body = bodyInit;
|
|
224
|
+
else if (bodyInit instanceof ArrayBuffer) body = Buffer.from(bodyInit);
|
|
225
|
+
else if (bodyInit instanceof Uint8Array) body = Buffer.from(bodyInit);
|
|
226
|
+
else if (bodyInit instanceof DataView) body = Buffer.from(bodyInit.buffer);
|
|
227
|
+
else if (bodyInit instanceof Blob) {
|
|
228
|
+
body = bodyInit.stream();
|
|
229
|
+
if (bodyInit.type) headers.push(["content-type", bodyInit.type]);
|
|
230
|
+
} else if (typeof bodyInit.pipe === "function") body = bodyInit;
|
|
231
|
+
else {
|
|
232
|
+
const res = new globalThis.Response(bodyInit);
|
|
233
|
+
body = res.body;
|
|
234
|
+
for (const [key, value] of res.headers) headers.push([key, value]);
|
|
235
|
+
}
|
|
236
|
+
this.#body = void 0;
|
|
237
|
+
this.#init = void 0;
|
|
238
|
+
this.#headersObj = void 0;
|
|
239
|
+
this.#responseObj = void 0;
|
|
240
|
+
return {
|
|
241
|
+
status,
|
|
242
|
+
statusText,
|
|
243
|
+
headers,
|
|
244
|
+
body
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/** Lazy initialized response instance */
|
|
248
|
+
#responseObj;
|
|
249
|
+
/** Lazy initialized headers instance */
|
|
250
|
+
#headersObj;
|
|
251
|
+
clone() {
|
|
252
|
+
if (this.#responseObj) return this.#responseObj.clone();
|
|
253
|
+
if (this.#headersObj) return new _Response(this.#body, {
|
|
254
|
+
...this.#init,
|
|
255
|
+
headers: this.#headersObj
|
|
256
|
+
});
|
|
257
|
+
return new _Response(this.#body, this.#init);
|
|
258
|
+
}
|
|
259
|
+
get #response() {
|
|
260
|
+
if (!this.#responseObj) {
|
|
261
|
+
this.#responseObj = this.#headersObj ? new globalThis.Response(this.#body, {
|
|
262
|
+
...this.#init,
|
|
263
|
+
headers: this.#headersObj
|
|
264
|
+
}) : new globalThis.Response(this.#body, this.#init);
|
|
265
|
+
this.#body = void 0;
|
|
266
|
+
this.#init = void 0;
|
|
267
|
+
this.#headersObj = void 0;
|
|
268
|
+
}
|
|
269
|
+
return this.#responseObj;
|
|
270
|
+
}
|
|
271
|
+
get headers() {
|
|
272
|
+
if (this.#responseObj) return this.#responseObj.headers;
|
|
273
|
+
if (!this.#headersObj) this.#headersObj = new Headers(this.#init?.headers);
|
|
274
|
+
return this.#headersObj;
|
|
275
|
+
}
|
|
276
|
+
get ok() {
|
|
277
|
+
if (this.#responseObj) return this.#responseObj.ok;
|
|
278
|
+
const status = this.#init?.status ?? 200;
|
|
279
|
+
return status >= 200 && status < 300;
|
|
280
|
+
}
|
|
281
|
+
get redirected() {
|
|
282
|
+
if (this.#responseObj) return this.#responseObj.redirected;
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
get status() {
|
|
286
|
+
if (this.#responseObj) return this.#responseObj.status;
|
|
287
|
+
return this.#init?.status ?? 200;
|
|
288
|
+
}
|
|
289
|
+
get statusText() {
|
|
290
|
+
if (this.#responseObj) return this.#responseObj.statusText;
|
|
291
|
+
return this.#init?.statusText ?? "";
|
|
292
|
+
}
|
|
293
|
+
get type() {
|
|
294
|
+
if (this.#responseObj) return this.#responseObj.type;
|
|
295
|
+
return "default";
|
|
296
|
+
}
|
|
297
|
+
get url() {
|
|
298
|
+
if (this.#responseObj) return this.#responseObj.url;
|
|
299
|
+
return "";
|
|
300
|
+
}
|
|
301
|
+
#fastBody(as) {
|
|
302
|
+
const bodyInit = this.#body;
|
|
303
|
+
if (bodyInit === null || bodyInit === void 0) return null;
|
|
304
|
+
if (bodyInit instanceof as) return bodyInit;
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
get body() {
|
|
308
|
+
if (this.#responseObj) return this.#responseObj.body;
|
|
309
|
+
const fastBody = this.#fastBody(ReadableStream);
|
|
310
|
+
if (fastBody !== false) return fastBody;
|
|
311
|
+
return this.#response.body;
|
|
312
|
+
}
|
|
313
|
+
get bodyUsed() {
|
|
314
|
+
if (this.#responseObj) return this.#responseObj.bodyUsed;
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
arrayBuffer() {
|
|
318
|
+
if (this.#responseObj) return this.#responseObj.arrayBuffer();
|
|
319
|
+
const fastBody = this.#fastBody(ArrayBuffer);
|
|
320
|
+
if (fastBody !== false) return Promise.resolve(fastBody || new ArrayBuffer(0));
|
|
321
|
+
return this.#response.arrayBuffer();
|
|
322
|
+
}
|
|
323
|
+
blob() {
|
|
324
|
+
if (this.#responseObj) return this.#responseObj.blob();
|
|
325
|
+
const fastBody = this.#fastBody(Blob);
|
|
326
|
+
if (fastBody !== false) return Promise.resolve(fastBody || new Blob());
|
|
327
|
+
return this.#response.blob();
|
|
328
|
+
}
|
|
329
|
+
bytes() {
|
|
330
|
+
if (this.#responseObj) return this.#responseObj.bytes();
|
|
331
|
+
const fastBody = this.#fastBody(Uint8Array);
|
|
332
|
+
if (fastBody !== false) return Promise.resolve(fastBody || new Uint8Array());
|
|
333
|
+
return this.#response.bytes();
|
|
334
|
+
}
|
|
335
|
+
formData() {
|
|
336
|
+
if (this.#responseObj) return this.#responseObj.formData();
|
|
337
|
+
const fastBody = this.#fastBody(FormData);
|
|
338
|
+
if (fastBody !== false) return Promise.resolve(fastBody || new FormData());
|
|
339
|
+
return this.#response.formData();
|
|
340
|
+
}
|
|
341
|
+
text() {
|
|
342
|
+
if (this.#responseObj) return this.#responseObj.text();
|
|
343
|
+
const bodyInit = this.#body;
|
|
344
|
+
if (bodyInit === null || bodyInit === void 0) return Promise.resolve("");
|
|
345
|
+
if (typeof bodyInit === "string") return Promise.resolve(bodyInit);
|
|
346
|
+
return this.#response.text();
|
|
347
|
+
}
|
|
348
|
+
json() {
|
|
349
|
+
if (this.#responseObj) return this.#responseObj.json();
|
|
350
|
+
return this.text().then((text) => JSON.parse(text));
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
Object.setPrototypeOf(_Response.prototype, globalThis.Response.prototype);
|
|
354
|
+
return _Response;
|
|
355
|
+
})();
|
|
356
|
+
|
|
357
|
+
//#endregion
|
|
358
|
+
export { NodeRequestHeaders, NodeResponse, NodeResponseHeaders, kNodeInspect };
|
|
@@ -250,6 +250,7 @@ type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.Net
|
|
|
250
250
|
type NodeServerRequest = NodeHttp$1.IncomingMessage | NodeHttp2.Http2ServerRequest;
|
|
251
251
|
type NodeServerResponse = NodeHttp$1.ServerResponse | NodeHttp2.Http2ServerResponse;
|
|
252
252
|
type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
|
|
253
|
+
type NodeHTTPMiddleware = (req: NodeServerRequest, res: NodeServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
|
|
253
254
|
type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
|
|
254
255
|
//#endregion
|
|
255
|
-
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve };
|
|
256
|
+
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve };
|
package/dist/adapters/bun.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
1
|
+
import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-BXtbU5Z8.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-D8u5OAto.mjs";
|
|
3
3
|
import * as bun from "bun";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/bun.d.ts
|
package/dist/adapters/deno.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
1
|
+
import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-BXtbU5Z8.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-D8u5OAto.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/deno.d.ts
|
|
5
5
|
declare const FastResponse: typeof globalThis.Response;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createWaitUntil } from "../_chunks/_utils-DRF_4b_y.mjs";
|
|
2
2
|
import { wrapFetch } from "../_chunks/_middleware-BvRR7B4M.mjs";
|
|
3
|
-
import { errorPlugin } from "../_chunks/_plugins-
|
|
3
|
+
import { errorPlugin } from "../_chunks/_plugins-DOhVIkXu.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/generic.ts
|
|
6
6
|
const FastURL = URL;
|
package/dist/adapters/node.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
1
|
+
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-BXtbU5Z8.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-D8u5OAto.mjs";
|
|
3
3
|
import NodeHttp from "node:http";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
5
|
|
|
@@ -39,7 +39,7 @@ declare const NodeResponse: {
|
|
|
39
39
|
status: number;
|
|
40
40
|
statusText: string;
|
|
41
41
|
headers: NodeHttp.OutgoingHttpHeader[];
|
|
42
|
-
body: string | Buffer | Uint8Array | DataView | ReadableStream
|
|
42
|
+
body: string | Buffer | Uint8Array | DataView | ReadableStream | Readable | undefined | null;
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
};
|