srvx 0.8.16 → 0.9.0
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 +1 -1
- package/dist/_chunks/{_inherit-aIijG5gM.mjs → _inherit-BoJ2sCH1.mjs} +1 -1
- package/dist/_chunks/{_url-6S_VTq5O.mjs → _url-DjsXG6si.mjs} +4 -1
- package/dist/_chunks/call-Ca6cbyoe.mjs +157 -0
- package/dist/_chunks/call-Ccm3CgTV.mjs +4 -0
- package/dist/_chunks/{types-vBo0F7mW.d.mts → types-4jUOEbJe.d.mts} +14 -10
- package/dist/adapters/bun.d.mts +3 -3
- package/dist/adapters/bun.mjs +4 -4
- package/dist/adapters/cloudflare.d.mts +1 -1
- package/dist/adapters/cloudflare.mjs +2 -2
- package/dist/adapters/deno.d.mts +2 -2
- package/dist/adapters/deno.mjs +4 -4
- package/dist/adapters/generic.d.mts +1 -1
- package/dist/adapters/generic.mjs +3 -3
- package/dist/adapters/node.d.mts +38 -22
- package/dist/adapters/node.mjs +423 -61
- package/dist/adapters/service-worker.d.mts +1 -1
- package/dist/adapters/service-worker.mjs +2 -2
- package/dist/cli.mjs +6 -10
- package/dist/log.d.mts +1 -1
- package/dist/static.d.mts +1 -1
- package/dist/static.mjs +4 -1
- package/dist/types.d.mts +1 -1
- package/package.json +16 -12
- package/dist/_chunks/call-_ai4zW1A.mjs +0 -45
- package/dist/_chunks/dist-BRKJ6i_Z.mjs +0 -45
- package/dist/_chunks/response-DKBPm3qF.mjs +0 -275
- package/dist/cookie.d.mts +0 -2
- package/dist/cookie.mjs +0 -3
- /package/dist/_chunks/{_middleware-z4fpJ-o6.mjs → _middleware-Z-W2xNSK.mjs} +0 -0
- /package/dist/_chunks/{_plugins-BuL6RXOq.mjs → _plugins-DOhVIkXu.mjs} +0 -0
- /package/dist/_chunks/{_url-AwIHDSW0.d.mts → _url-D-jAQyRZ.d.mts} +0 -0
- /package/dist/_chunks/{_utils-DEm1vdc3.mjs → _utils-dqVgpDNy.mjs} +0 -0
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Universal Server based on web standards. Works with [Deno](https://deno.com/), [
|
|
|
13
13
|
- ✅ Zero dependency
|
|
14
14
|
- ✅ Full featured CLI with watcher, error handler, serve static and logger
|
|
15
15
|
- ✅ Seamless runtime integration with same API ([handler](https://srvx.h3.dev/guide/handler) and [instance](https://srvx.h3.dev/guide/server)).
|
|
16
|
-
- ✅ [Node.js compatibility](https://srvx.h3.dev/guide/node) with
|
|
16
|
+
- ✅ [Node.js compatibility](https://srvx.h3.dev/guide/node) with a [**close to native performance**](https://github.com/h3js/srvx/tree/main/test/bench-node).
|
|
17
17
|
- ✅ Zero overhead [Deno](https://deno.com/) and [Bun](https://bun.sh/) support.
|
|
18
18
|
|
|
19
19
|
## Quick start
|
|
@@ -17,7 +17,7 @@ function lazyInherit(target, source, sourceKey) {
|
|
|
17
17
|
this[sourceKey][key] = value;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
if (typeof desc.value === "function") {
|
|
20
|
+
if (!targetDesc?.value && typeof desc.value === "function") {
|
|
21
21
|
modified = true;
|
|
22
22
|
desc.value = function(...args) {
|
|
23
23
|
return this[sourceKey][key](...args);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lazyInherit } from "./_inherit-
|
|
1
|
+
import { lazyInherit } from "./_inherit-BoJ2sCH1.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/_url.ts
|
|
4
4
|
/**
|
|
@@ -35,6 +35,9 @@ const FastURL = /* @__PURE__ */ (() => {
|
|
|
35
35
|
this.#search = url.search;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
static [Symbol.hasInstance](val) {
|
|
39
|
+
return val instanceof NativeURL;
|
|
40
|
+
}
|
|
38
41
|
get _url() {
|
|
39
42
|
if (this.#url) return this.#url;
|
|
40
43
|
this.#url = new NativeURL(this.href);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { lazyInherit } from "./_inherit-BoJ2sCH1.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/_node/response.ts
|
|
4
|
+
/**
|
|
5
|
+
* Fast Response for Node.js runtime
|
|
6
|
+
*
|
|
7
|
+
* It is faster because in most cases it doesn't create a full Response instance.
|
|
8
|
+
*/
|
|
9
|
+
const NodeResponse = /* @__PURE__ */ (() => {
|
|
10
|
+
const NativeResponse = globalThis.Response;
|
|
11
|
+
const STATUS_CODES = globalThis.process?.getBuiltinModule?.("node:http")?.STATUS_CODES || {};
|
|
12
|
+
class NodeResponse$1 {
|
|
13
|
+
#body;
|
|
14
|
+
#init;
|
|
15
|
+
#headers;
|
|
16
|
+
#response;
|
|
17
|
+
constructor(body, init) {
|
|
18
|
+
this.#body = body;
|
|
19
|
+
this.#init = init;
|
|
20
|
+
}
|
|
21
|
+
static [Symbol.hasInstance](val) {
|
|
22
|
+
return val instanceof NativeResponse;
|
|
23
|
+
}
|
|
24
|
+
get status() {
|
|
25
|
+
return this.#response?.status || this.#init?.status || 200;
|
|
26
|
+
}
|
|
27
|
+
get statusText() {
|
|
28
|
+
return this.#response?.statusText || this.#init?.statusText || STATUS_CODES[this.status] || "";
|
|
29
|
+
}
|
|
30
|
+
get headers() {
|
|
31
|
+
if (this.#response) return this.#response.headers;
|
|
32
|
+
if (this.#headers) return this.#headers;
|
|
33
|
+
const initHeaders = this.#init?.headers;
|
|
34
|
+
return this.#headers = initHeaders instanceof Headers ? initHeaders : new Headers(initHeaders);
|
|
35
|
+
}
|
|
36
|
+
get ok() {
|
|
37
|
+
if (this.#response) return this.#response.ok;
|
|
38
|
+
const status = this.status;
|
|
39
|
+
return status >= 200 && status < 300;
|
|
40
|
+
}
|
|
41
|
+
get _response() {
|
|
42
|
+
if (this.#response) return this.#response;
|
|
43
|
+
this.#response = new NativeResponse(this.#body, this.#headers ? {
|
|
44
|
+
...this.#init,
|
|
45
|
+
headers: this.#headers
|
|
46
|
+
} : this.#init);
|
|
47
|
+
this.#init = void 0;
|
|
48
|
+
this.#headers = void 0;
|
|
49
|
+
this.#body = void 0;
|
|
50
|
+
return this.#response;
|
|
51
|
+
}
|
|
52
|
+
_toNodeResponse() {
|
|
53
|
+
const status = this.status;
|
|
54
|
+
const statusText = this.statusText;
|
|
55
|
+
let body;
|
|
56
|
+
let contentType;
|
|
57
|
+
let contentLength;
|
|
58
|
+
if (this.#response) body = this.#response.body;
|
|
59
|
+
else if (this.#body) if (this.#body instanceof ReadableStream) body = this.#body;
|
|
60
|
+
else if (typeof this.#body === "string") {
|
|
61
|
+
body = this.#body;
|
|
62
|
+
contentType = "text/plain; charset=UTF-8";
|
|
63
|
+
contentLength = Buffer.byteLength(this.#body);
|
|
64
|
+
} else if (this.#body instanceof ArrayBuffer) {
|
|
65
|
+
body = Buffer.from(this.#body);
|
|
66
|
+
contentLength = this.#body.byteLength;
|
|
67
|
+
} else if (this.#body instanceof Uint8Array) {
|
|
68
|
+
body = this.#body;
|
|
69
|
+
contentLength = this.#body.byteLength;
|
|
70
|
+
} else if (this.#body instanceof DataView) {
|
|
71
|
+
body = Buffer.from(this.#body.buffer);
|
|
72
|
+
contentLength = this.#body.byteLength;
|
|
73
|
+
} else if (this.#body instanceof Blob) {
|
|
74
|
+
body = this.#body.stream();
|
|
75
|
+
contentType = this.#body.type;
|
|
76
|
+
contentLength = this.#body.size;
|
|
77
|
+
} else if (typeof this.#body.pipe === "function") body = this.#body;
|
|
78
|
+
else body = this._response.body;
|
|
79
|
+
const headers = [];
|
|
80
|
+
const initHeaders = this.#init?.headers;
|
|
81
|
+
const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders).map(([k, v]) => [k.toLowerCase(), v]) : void 0);
|
|
82
|
+
let hasContentTypeHeader;
|
|
83
|
+
let hasContentLength;
|
|
84
|
+
if (headerEntries) for (const [key, value] of headerEntries) {
|
|
85
|
+
if (Array.isArray(value)) for (const v of value) headers.push([key, v]);
|
|
86
|
+
else headers.push([key, value]);
|
|
87
|
+
if (key === "content-type") hasContentTypeHeader = true;
|
|
88
|
+
else if (key === "content-length") hasContentLength = true;
|
|
89
|
+
}
|
|
90
|
+
if (contentType && !hasContentTypeHeader) headers.push(["content-type", contentType]);
|
|
91
|
+
if (contentLength && !hasContentLength) headers.push(["content-length", String(contentLength)]);
|
|
92
|
+
this.#init = void 0;
|
|
93
|
+
this.#headers = void 0;
|
|
94
|
+
this.#response = void 0;
|
|
95
|
+
this.#body = void 0;
|
|
96
|
+
return {
|
|
97
|
+
status,
|
|
98
|
+
statusText,
|
|
99
|
+
headers,
|
|
100
|
+
body
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
lazyInherit(NodeResponse$1.prototype, NativeResponse.prototype, "_response");
|
|
105
|
+
Object.setPrototypeOf(NodeResponse$1, NativeResponse);
|
|
106
|
+
Object.setPrototypeOf(NodeResponse$1.prototype, NativeResponse.prototype);
|
|
107
|
+
return NodeResponse$1;
|
|
108
|
+
})();
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/adapters/_node/call.ts
|
|
112
|
+
function callNodeHandler(handler, req) {
|
|
113
|
+
const isMiddleware = handler.length > 2;
|
|
114
|
+
const nodeCtx = req.runtime?.node;
|
|
115
|
+
if (!nodeCtx || !nodeCtx.req || !nodeCtx.res) throw new Error("Node.js runtime context is not available.");
|
|
116
|
+
const { req: nodeReq, res: nodeRes } = nodeCtx;
|
|
117
|
+
let _headers;
|
|
118
|
+
const webRes = new NodeResponse(void 0, {
|
|
119
|
+
get status() {
|
|
120
|
+
return nodeRes.statusCode;
|
|
121
|
+
},
|
|
122
|
+
get statusText() {
|
|
123
|
+
return nodeRes.statusMessage;
|
|
124
|
+
},
|
|
125
|
+
get headers() {
|
|
126
|
+
if (!_headers) {
|
|
127
|
+
const headerEntries = [];
|
|
128
|
+
const rawHeaders = nodeRes.getHeaders();
|
|
129
|
+
for (const [name, value] of Object.entries(rawHeaders)) if (Array.isArray(value)) for (const v of value) headerEntries.push([name, v]);
|
|
130
|
+
else if (value) headerEntries.push([name, String(value)]);
|
|
131
|
+
_headers = new Headers(headerEntries);
|
|
132
|
+
}
|
|
133
|
+
return _headers;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
nodeRes.once("close", () => resolve(webRes));
|
|
138
|
+
nodeRes.once("finish", () => resolve(webRes));
|
|
139
|
+
nodeRes.once("error", (error) => reject(error));
|
|
140
|
+
let streamPromise;
|
|
141
|
+
nodeRes.once("pipe", (stream) => {
|
|
142
|
+
streamPromise = new Promise((resolve$1) => {
|
|
143
|
+
stream.once("end", () => resolve$1(webRes));
|
|
144
|
+
stream.once("error", (error) => reject(error));
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
if (isMiddleware) Promise.resolve(handler(nodeReq, nodeRes, (error) => error ? reject(error) : streamPromise || resolve(webRes))).catch((error) => reject(error));
|
|
149
|
+
else Promise.resolve(handler(nodeReq, nodeRes)).then(() => streamPromise || webRes);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
reject(error);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
export { NodeResponse, callNodeHandler };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as NodeHttp$1 from "node:http";
|
|
1
|
+
import * as NodeHttp from "node:http";
|
|
3
2
|
import * as NodeHttps from "node:https";
|
|
4
3
|
import * as NodeHttp2 from "node:http2";
|
|
4
|
+
import * as cloudflare_workers0 from "cloudflare:workers";
|
|
5
5
|
import * as NodeNet from "node:net";
|
|
6
6
|
import * as Bun from "bun";
|
|
7
7
|
import * as CF from "@cloudflare/workers-types";
|
|
@@ -112,7 +112,7 @@ interface ServerOptions {
|
|
|
112
112
|
/**
|
|
113
113
|
* Node.js server options.
|
|
114
114
|
*/
|
|
115
|
-
node?: (NodeHttp
|
|
115
|
+
node?: (NodeHttp.ServerOptions | NodeHttps.ServerOptions | NodeHttp2.ServerOptions) & NodeNet.ListenOptions & {
|
|
116
116
|
http2?: boolean;
|
|
117
117
|
};
|
|
118
118
|
/**
|
|
@@ -120,7 +120,7 @@ interface ServerOptions {
|
|
|
120
120
|
*
|
|
121
121
|
* @docs https://bun.sh/docs/api/http
|
|
122
122
|
*/
|
|
123
|
-
bun?: Omit<Bun.
|
|
123
|
+
bun?: Omit<Bun.Serve.Options<any>, "fetch">;
|
|
124
124
|
/**
|
|
125
125
|
* Deno server options
|
|
126
126
|
*
|
|
@@ -161,14 +161,14 @@ interface Server<Handler = ServerHandler> {
|
|
|
161
161
|
* Node.js context.
|
|
162
162
|
*/
|
|
163
163
|
readonly node?: {
|
|
164
|
-
server?: NodeHttp
|
|
164
|
+
server?: NodeHttp.Server | NodeHttp2.Http2Server;
|
|
165
165
|
handler: (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
|
|
166
166
|
};
|
|
167
167
|
/**
|
|
168
168
|
* Bun context.
|
|
169
169
|
*/
|
|
170
170
|
readonly bun?: {
|
|
171
|
-
server?: Bun.Server
|
|
171
|
+
server?: Bun.Server<any>;
|
|
172
172
|
};
|
|
173
173
|
/**
|
|
174
174
|
* Deno context.
|
|
@@ -221,7 +221,7 @@ interface ServerRuntimeContext {
|
|
|
221
221
|
* Underlying Bun server request context.
|
|
222
222
|
*/
|
|
223
223
|
bun?: {
|
|
224
|
-
server: Bun.Server
|
|
224
|
+
server: Bun.Server<any>;
|
|
225
225
|
};
|
|
226
226
|
/**
|
|
227
227
|
* Underlying Cloudflare request context.
|
|
@@ -235,6 +235,10 @@ interface ServerRequestContext {
|
|
|
235
235
|
[key: string]: unknown;
|
|
236
236
|
}
|
|
237
237
|
interface ServerRequest extends Request {
|
|
238
|
+
/**
|
|
239
|
+
* Access to the parsed URL
|
|
240
|
+
*/
|
|
241
|
+
_url?: URL;
|
|
238
242
|
/**
|
|
239
243
|
* Runtime specific request context.
|
|
240
244
|
*/
|
|
@@ -257,10 +261,10 @@ interface ServerRequest extends Request {
|
|
|
257
261
|
// ----------------------------------------------------------------------------
|
|
258
262
|
type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
259
263
|
type ErrorHandler = (error: unknown) => Response | Promise<Response>;
|
|
260
|
-
type BunFetchHandler = (request: Request, server?: Bun.Server) => Response | Promise<Response>;
|
|
264
|
+
type BunFetchHandler = (request: Request, server?: Bun.Server<any>) => Response | Promise<Response>;
|
|
261
265
|
type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.NetAddr>) => Response | Promise<Response>;
|
|
262
|
-
type NodeServerRequest = NodeHttp
|
|
263
|
-
type NodeServerResponse = NodeHttp
|
|
266
|
+
type NodeServerRequest = NodeHttp.IncomingMessage | NodeHttp2.Http2ServerRequest;
|
|
267
|
+
type NodeServerResponse = NodeHttp.ServerResponse | NodeHttp2.Http2ServerResponse;
|
|
264
268
|
type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
|
|
265
269
|
type NodeHTTPMiddleware = (req: NodeServerRequest, res: NodeServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
|
|
266
270
|
type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
|
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-4jUOEbJe.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-D-jAQyRZ.mjs";
|
|
3
3
|
import * as bun from "bun";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/bun.d.ts
|
|
@@ -11,7 +11,7 @@ declare class BunServer implements Server<BunFetchHandler> {
|
|
|
11
11
|
readonly runtime = "bun";
|
|
12
12
|
readonly options: Server["options"];
|
|
13
13
|
readonly bun: Server["bun"];
|
|
14
|
-
readonly serveOptions: bun.
|
|
14
|
+
readonly serveOptions: bun.Serve.Options<any>;
|
|
15
15
|
readonly fetch: BunFetchHandler;
|
|
16
16
|
constructor(options: ServerOptions);
|
|
17
17
|
serve(): Promise<this>;
|
package/dist/adapters/bun.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import "../_chunks/
|
|
4
|
-
import {
|
|
1
|
+
import "../_chunks/_inherit-BoJ2sCH1.mjs";
|
|
2
|
+
import { FastURL$1 as FastURL } from "../_chunks/_url-DjsXG6si.mjs";
|
|
3
|
+
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-dqVgpDNy.mjs";
|
|
4
|
+
import { wrapFetch } from "../_chunks/_middleware-Z-W2xNSK.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/bun.ts
|
|
7
7
|
const FastResponse = Response;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { wrapFetch } from "../_chunks/_middleware-
|
|
2
|
-
import { errorPlugin } from "../_chunks/_plugins-
|
|
1
|
+
import { wrapFetch } from "../_chunks/_middleware-Z-W2xNSK.mjs";
|
|
2
|
+
import { errorPlugin } from "../_chunks/_plugins-DOhVIkXu.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/cloudflare.ts
|
|
5
5
|
const FastURL = URL;
|
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-4jUOEbJe.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-D-jAQyRZ.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/deno.d.ts
|
|
5
5
|
declare const FastResponse: typeof globalThis.Response;
|
package/dist/adapters/deno.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import "../_chunks/
|
|
4
|
-
import {
|
|
1
|
+
import "../_chunks/_inherit-BoJ2sCH1.mjs";
|
|
2
|
+
import { FastURL$1 as FastURL } from "../_chunks/_url-DjsXG6si.mjs";
|
|
3
|
+
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-dqVgpDNy.mjs";
|
|
4
|
+
import { wrapFetch } from "../_chunks/_middleware-Z-W2xNSK.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/deno.ts
|
|
7
7
|
const FastResponse = Response;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createWaitUntil } from "../_chunks/_utils-
|
|
2
|
-
import { wrapFetch } from "../_chunks/_middleware-
|
|
3
|
-
import { errorPlugin } from "../_chunks/_plugins-
|
|
1
|
+
import { createWaitUntil } from "../_chunks/_utils-dqVgpDNy.mjs";
|
|
2
|
+
import { wrapFetch } from "../_chunks/_middleware-Z-W2xNSK.mjs";
|
|
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,6 +1,5 @@
|
|
|
1
|
-
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
3
|
-
import NodeHttp from "node:http";
|
|
1
|
+
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-4jUOEbJe.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-D-jAQyRZ.mjs";
|
|
4
3
|
import { Readable } from "node:stream";
|
|
5
4
|
|
|
6
5
|
//#region src/adapters/_node/request.d.ts
|
|
@@ -12,28 +11,13 @@ declare const NodeRequest: {
|
|
|
12
11
|
new (nodeCtx: NodeRequestContext): ServerRequest;
|
|
13
12
|
};
|
|
14
13
|
//#endregion
|
|
15
|
-
//#region src/adapters/_node/headers.d.ts
|
|
16
|
-
type NodeRequestHeaders = InstanceType<typeof NodeRequestHeaders>;
|
|
17
|
-
declare const NodeRequestHeaders: {
|
|
18
|
-
new (nodeCtx: {
|
|
19
|
-
req: NodeServerRequest;
|
|
20
|
-
res?: NodeServerResponse;
|
|
21
|
-
}): globalThis.Headers;
|
|
22
|
-
};
|
|
23
|
-
declare const NodeResponseHeaders: {
|
|
24
|
-
new (nodeCtx: {
|
|
25
|
-
req?: NodeServerRequest;
|
|
26
|
-
res: NodeServerResponse;
|
|
27
|
-
}): globalThis.Headers;
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
14
|
//#region src/adapters/_node/response.d.ts
|
|
31
15
|
// prettier-ignore
|
|
32
16
|
type PreparedNodeResponseBody = string | Buffer | Uint8Array | DataView | ReadableStream | Readable | undefined | null;
|
|
33
17
|
interface PreparedNodeResponse {
|
|
34
18
|
status: number;
|
|
35
19
|
statusText: string;
|
|
36
|
-
headers:
|
|
20
|
+
headers: [string, string][];
|
|
37
21
|
body: PreparedNodeResponseBody;
|
|
38
22
|
}
|
|
39
23
|
/**
|
|
@@ -43,7 +27,7 @@ interface PreparedNodeResponse {
|
|
|
43
27
|
*/
|
|
44
28
|
declare const NodeResponse: {
|
|
45
29
|
new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response & {
|
|
46
|
-
|
|
30
|
+
_toNodeResponse: () => PreparedNodeResponse;
|
|
47
31
|
};
|
|
48
32
|
};
|
|
49
33
|
type NodeResponse = InstanceType<typeof NodeResponse>;
|
|
@@ -51,8 +35,40 @@ type NodeResponse = InstanceType<typeof NodeResponse>;
|
|
|
51
35
|
//#region src/adapters/_node/send.d.ts
|
|
52
36
|
declare function sendNodeResponse(nodeRes: NodeServerResponse, webRes: Response | NodeResponse): Promise<void>;
|
|
53
37
|
//#endregion
|
|
38
|
+
//#region src/adapters/_node/web/fetch.d.ts
|
|
39
|
+
// https://github.com/nodejs/node/blob/main/lib/_http_incoming.js
|
|
40
|
+
// https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js
|
|
41
|
+
// https://github.com/nodejs/node/blob/main/lib/_http_server.js
|
|
42
|
+
/**
|
|
43
|
+
* Calls a Node.js HTTP Request handler with a Fetch API Request object and returns a Response object.
|
|
44
|
+
*
|
|
45
|
+
* If the web Request contains an existing Node.js req/res pair (indicating it originated from a Node.js server from srvx/node), it will be called directly.
|
|
46
|
+
*
|
|
47
|
+
* Otherwise, new Node.js IncomingMessage and ServerResponse objects are created and linked to a custom Duplex stream that bridges the Fetch API streams with Node.js streams.
|
|
48
|
+
*
|
|
49
|
+
* The handler is invoked with these objects, and the response is constructed from the ServerResponse once it is finished.
|
|
50
|
+
*
|
|
51
|
+
* @experimental Behavior might be unstable.
|
|
52
|
+
*/
|
|
53
|
+
declare function fetchNodeHandler(handler: NodeHttpHandler, req: ServerRequest): Promise<Response>;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/adapters/_node/adapter.d.ts
|
|
56
|
+
type AdapterMeta = {
|
|
57
|
+
__nodeHandler?: NodeHttpHandler;
|
|
58
|
+
__fetchHandler?: FetchHandler;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Converts a Fetch API handler to a Node.js HTTP handler.
|
|
62
|
+
*/
|
|
63
|
+
declare function toNodeHandler(handler: FetchHandler & AdapterMeta): NodeHttpHandler & AdapterMeta;
|
|
64
|
+
/**
|
|
65
|
+
* Converts a Node.js HTTP handler into a Fetch API handler.
|
|
66
|
+
*
|
|
67
|
+
* @experimental Behavior might be unstable and won't work in Bun and Deno currently (tracker: https://github.com/h3js/srvx/issues/132)
|
|
68
|
+
*/
|
|
69
|
+
declare function toFetchHandler(handler: NodeHttpHandler & AdapterMeta): FetchHandler & AdapterMeta;
|
|
70
|
+
//#endregion
|
|
54
71
|
//#region src/adapters/node.d.ts
|
|
55
72
|
declare function serve(options: ServerOptions): Server;
|
|
56
|
-
declare function toNodeHandler(fetchHandler: FetchHandler): NodeHttpHandler;
|
|
57
73
|
//#endregion
|
|
58
|
-
export { NodeResponse as FastResponse, FastURL, NodeRequest,
|
|
74
|
+
export { NodeResponse as FastResponse, FastURL, NodeRequest, NodeResponse, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
|