srvx 0.9.8 → 0.10.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.
@@ -239,6 +239,12 @@ interface ServerRequestContext {
239
239
  [key: string]: unknown;
240
240
  }
241
241
  interface ServerRequest extends Request {
242
+ /**
243
+ * Access to Node.js native instance of request.
244
+ *
245
+ * See https://srvx.h3.dev/guide/node#noderequest
246
+ */
247
+ _request?: Request;
242
248
  /**
243
249
  * Access to the parsed URL
244
250
  */
@@ -266,8 +272,12 @@ type BunFetchHandler = (request: Request, server?: Bun.Server<any>) => Response
266
272
  type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.NetAddr>) => Response | Promise<Response>;
267
273
  type NodeServerRequest = NodeHttp.IncomingMessage | NodeHttp2.Http2ServerRequest;
268
274
  type NodeServerResponse = NodeHttp.ServerResponse | NodeHttp2.Http2ServerResponse;
269
- type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
270
- type NodeHTTPMiddleware = (req: NodeServerRequest, res: NodeServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
275
+ type NodeHttp1Handler = (req: NodeHttp.IncomingMessage, res: NodeHttp.ServerResponse) => void | Promise<void>;
276
+ type NodeHttp2Handler = (req: NodeHttp2.Http2ServerRequest, res: NodeHttp2.Http2ServerResponse) => void | Promise<void>;
277
+ type NodeHttpHandler = NodeHttp1Handler | NodeHttp2Handler;
278
+ type NodeHTTP1Middleware = (req: NodeHttp.IncomingMessage, res: NodeHttp.ServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
279
+ type NodeHTTP2Middleware = (req: NodeHttp2.Http2ServerRequest, res: NodeHttp2.Http2ServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
280
+ type NodeHTTPMiddleware = NodeHTTP1Middleware | NodeHTTP2Middleware;
271
281
  type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
272
282
  //#endregion
273
- export { ServerRequest as _, FastResponse as a, serve as b, NodeHTTPMiddleware as c, NodeServerResponse as d, Server as f, ServerPlugin as g, ServerOptions as h, ErrorHandler as i, NodeHttpHandler as l, ServerMiddleware as m, CloudflareFetchHandler as n, FastURL as o, ServerHandler as p, DenoFetchHandler as r, FetchHandler as s, BunFetchHandler as t, NodeServerRequest as u, ServerRequestContext as v, ServerRuntimeContext as y };
283
+ export { ServerRuntimeContext as C, ServerRequestContext as S, ServerHandler as _, FastResponse as a, ServerPlugin as b, NodeHTTP1Middleware as c, NodeHttp1Handler as d, NodeHttp2Handler as f, Server as g, NodeServerResponse as h, ErrorHandler as i, NodeHTTP2Middleware as l, NodeServerRequest as m, CloudflareFetchHandler as n, FastURL as o, NodeHttpHandler as p, DenoFetchHandler as r, FetchHandler as s, BunFetchHandler as t, NodeHTTPMiddleware as u, ServerMiddleware as v, serve as w, ServerRequest as x, ServerOptions as y };
@@ -1,4 +1,4 @@
1
- import { f as Server, h as ServerOptions, t as BunFetchHandler } from "../_chunks/types.mjs";
1
+ import { g as Server, t as BunFetchHandler, y as ServerOptions } from "../_chunks/types.mjs";
2
2
  import { t as FastURL } from "../_chunks/_url.mjs";
3
3
  import * as bun from "bun";
4
4
 
@@ -1,4 +1,4 @@
1
- import { f as Server, h as ServerOptions } from "../_chunks/types.mjs";
1
+ import { g as Server, y as ServerOptions } from "../_chunks/types.mjs";
2
2
  import * as CF from "@cloudflare/workers-types";
3
3
 
4
4
  //#region src/adapters/cloudflare.d.ts
@@ -1,4 +1,4 @@
1
- import { f as Server, h as ServerOptions, r as DenoFetchHandler } from "../_chunks/types.mjs";
1
+ import { g as Server, r as DenoFetchHandler, y as ServerOptions } from "../_chunks/types.mjs";
2
2
  import { t as FastURL } from "../_chunks/_url.mjs";
3
3
 
4
4
  //#region src/adapters/deno.d.ts
@@ -1,4 +1,4 @@
1
- import { f as Server, h as ServerOptions } from "../_chunks/types.mjs";
1
+ import { g as Server, y as ServerOptions } from "../_chunks/types.mjs";
2
2
 
3
3
  //#region src/adapters/generic.d.ts
4
4
  declare const FastURL: typeof globalThis.URL;
@@ -1,4 +1,4 @@
1
- import { _ as ServerRequest, d as NodeServerResponse, f as Server, h as ServerOptions, l as NodeHttpHandler, s as FetchHandler, u as NodeServerRequest } from "../_chunks/types.mjs";
1
+ import { g as Server, h as NodeServerResponse, m as NodeServerRequest, p as NodeHttpHandler, s as FetchHandler, x as ServerRequest, y as ServerOptions } from "../_chunks/types.mjs";
2
2
  import { t as FastURL } from "../_chunks/_url.mjs";
3
3
  import { Readable } from "node:stream";
4
4
 
@@ -10,6 +10,14 @@ type NodeRequestContext = {
10
10
  declare const NodeRequest: {
11
11
  new (nodeCtx: NodeRequestContext): ServerRequest;
12
12
  };
13
+ /**
14
+ * Undici uses an incompatible Request constructor depending on private property accessors.
15
+ *
16
+ * This utility, patches global Request to support `new Request(req)` in Node.js.
17
+ *
18
+ * Alternatively you can use `new Request(req._request || req)` instead of patching global Request.
19
+ */
20
+ declare function patchGlobalRequest(): typeof Request;
13
21
  //#endregion
14
22
  //#region src/adapters/_node/response.d.ts
15
23
  type PreparedNodeResponseBody = string | Buffer | Uint8Array | DataView | ReadableStream | Readable | undefined | null;
@@ -67,4 +75,4 @@ declare function toFetchHandler(handler: NodeHttpHandler & AdapterMeta): FetchHa
67
75
  //#region src/adapters/node.d.ts
68
76
  declare function serve(options: ServerOptions): Server;
69
77
  //#endregion
70
- export { type AdapterMeta, NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
78
+ export { type AdapterMeta, NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
@@ -164,20 +164,7 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
164
164
  //#endregion
165
165
  //#region src/adapters/_node/request.ts
166
166
  const NodeRequest = /* @__PURE__ */ (() => {
167
- const NativeRequest = globalThis[Symbol.for("srvx.nativeRequest")] ??= globalThis.Request;
168
- const PatchedRequest = class Request$1 extends NativeRequest {
169
- static _srvx = true;
170
- static [Symbol.hasInstance](instance) {
171
- if (this === PatchedRequest) return instance instanceof NativeRequest;
172
- else return Object.prototype.isPrototypeOf.call(this.prototype, instance);
173
- }
174
- constructor(input, options) {
175
- if (typeof input === "object" && "_request" in input) input = input._request;
176
- if ((options?.body)?.getReader !== void 0) options.duplex ??= "half";
177
- super(input, options);
178
- }
179
- };
180
- if (!globalThis.Request._srvx) globalThis.Request = PatchedRequest;
167
+ const NativeRequest = globalThis.Request;
181
168
  class Request {
182
169
  runtime;
183
170
  #req;
@@ -257,11 +244,13 @@ const NodeRequest = /* @__PURE__ */ (() => {
257
244
  }
258
245
  get _request() {
259
246
  if (!this.#request) {
260
- this.#request = new PatchedRequest(this.url, {
247
+ const body = this.body;
248
+ this.#request = new NativeRequest(this.url, {
261
249
  method: this.method,
262
250
  headers: this.headers,
263
- body: this.body,
264
- signal: this._abortController.signal
251
+ signal: this._abortController.signal,
252
+ body,
253
+ duplex: body ? "half" : void 0
265
254
  });
266
255
  this.#headers = void 0;
267
256
  this.#bodyStream = void 0;
@@ -273,6 +262,29 @@ const NodeRequest = /* @__PURE__ */ (() => {
273
262
  Object.setPrototypeOf(Request.prototype, NativeRequest.prototype);
274
263
  return Request;
275
264
  })();
265
+ /**
266
+ * Undici uses an incompatible Request constructor depending on private property accessors.
267
+ *
268
+ * This utility, patches global Request to support `new Request(req)` in Node.js.
269
+ *
270
+ * Alternatively you can use `new Request(req._request || req)` instead of patching global Request.
271
+ */
272
+ function patchGlobalRequest() {
273
+ const NativeRequest = globalThis[Symbol.for("srvx.nativeRequest")] ??= globalThis.Request;
274
+ const PatchedRequest = class Request extends NativeRequest {
275
+ static _srvx = true;
276
+ static [Symbol.hasInstance](instance) {
277
+ if (this === PatchedRequest) return instance instanceof NativeRequest;
278
+ else return Object.prototype.isPrototypeOf.call(this.prototype, instance);
279
+ }
280
+ constructor(input, options) {
281
+ if (typeof input === "object" && "_request" in input) input = input._request;
282
+ super(input, options);
283
+ }
284
+ };
285
+ if (!globalThis.Request._srvx) globalThis.Request = PatchedRequest;
286
+ return PatchedRequest;
287
+ }
276
288
  function readBody(req) {
277
289
  return new Promise((resolve, reject) => {
278
290
  const chunks = [];
@@ -637,4 +649,4 @@ var NodeServer = class {
637
649
  };
638
650
 
639
651
  //#endregion
640
- export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
652
+ export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
@@ -1,4 +1,4 @@
1
- import { _ as ServerRequest, f as Server, h as ServerOptions } from "../_chunks/types.mjs";
1
+ import { g as Server, x as ServerRequest, y as ServerOptions } from "../_chunks/types.mjs";
2
2
 
3
3
  //#region src/adapters/service-worker.d.ts
4
4
  declare const FastURL: typeof globalThis.URL;
package/dist/log.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { m as ServerMiddleware } from "./_chunks/types.mjs";
1
+ import { v as ServerMiddleware } from "./_chunks/types.mjs";
2
2
 
3
3
  //#region src/log.d.ts
4
4
  interface LogOptions {}
package/dist/static.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { m as ServerMiddleware } from "./_chunks/types.mjs";
1
+ import { v as ServerMiddleware } from "./_chunks/types.mjs";
2
2
 
3
3
  //#region src/static.d.ts
4
4
  interface ServeStaticOptions {
@@ -1,4 +1,4 @@
1
- import { _ as ServerRequest, f as Server, g as ServerPlugin, m as ServerMiddleware } from "./_chunks/types.mjs";
1
+ import { b as ServerPlugin, g as Server, v as ServerMiddleware, x as ServerRequest } from "./_chunks/types.mjs";
2
2
 
3
3
  //#region src/tracing.d.ts
4
4
 
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as ServerRequest, a as FastResponse, b as serve, c as NodeHTTPMiddleware, d as NodeServerResponse, f as Server, g as ServerPlugin, h as ServerOptions, i as ErrorHandler, l as NodeHttpHandler, m as ServerMiddleware, n as CloudflareFetchHandler, o as FastURL, p as ServerHandler, r as DenoFetchHandler, s as FetchHandler, t as BunFetchHandler, u as NodeServerRequest, v as ServerRequestContext, y as ServerRuntimeContext } from "./_chunks/types.mjs";
2
- export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve };
1
+ import { C as ServerRuntimeContext, S as ServerRequestContext, _ as ServerHandler, a as FastResponse, b as ServerPlugin, c as NodeHTTP1Middleware, d as NodeHttp1Handler, f as NodeHttp2Handler, g as Server, h as NodeServerResponse, i as ErrorHandler, l as NodeHTTP2Middleware, m as NodeServerRequest, n as CloudflareFetchHandler, o as FastURL, p as NodeHttpHandler, r as DenoFetchHandler, s as FetchHandler, t as BunFetchHandler, u as NodeHTTPMiddleware, v as ServerMiddleware, w as serve, x as ServerRequest, y as ServerOptions } from "./_chunks/types.mjs";
2
+ export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTP1Middleware, NodeHTTP2Middleware, NodeHTTPMiddleware, NodeHttp1Handler, NodeHttp2Handler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "srvx",
3
- "version": "0.9.8",
3
+ "version": "0.10.0",
4
4
  "description": "Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.",
5
5
  "homepage": "https://srvx.h3.dev",
6
6
  "repository": "h3js/srvx",
@@ -59,21 +59,21 @@
59
59
  "srvx": "link:."
60
60
  },
61
61
  "devDependencies": {
62
- "@cloudflare/workers-types": "^4.20251210.0",
62
+ "@cloudflare/workers-types": "^4.20251230.0",
63
63
  "@hono/node-server": "^1.19.7",
64
64
  "@mitata/counters": "^0.0.8",
65
65
  "@mjackson/node-fetch-server": "^0.7.0",
66
- "@types/bun": "^1.3.4",
66
+ "@types/bun": "^1.3.5",
67
67
  "@types/deno": "^2.5.0",
68
68
  "@types/express": "^5.0.6",
69
- "@types/node": "^25.0.0",
69
+ "@types/node": "^25.0.3",
70
70
  "@types/node-forge": "^1.3.14",
71
- "@types/serviceworker": "^0.0.168",
72
- "@vitest/coverage-v8": "^4.0.15",
71
+ "@types/serviceworker": "^0.0.172",
72
+ "@vitest/coverage-v8": "^4.0.16",
73
73
  "@whatwg-node/server": "^0.10.17",
74
74
  "automd": "^0.4.2",
75
75
  "changelogen": "^0.6.2",
76
- "eslint": "^9.39.1",
76
+ "eslint": "^9.39.2",
77
77
  "eslint-config-unjs": "^0.5.0",
78
78
  "execa": "^9.6.1",
79
79
  "express": "^5.2.1",
@@ -82,15 +82,15 @@
82
82
  "mdbox": "^0.1.1",
83
83
  "mitata": "^1.0.34",
84
84
  "node-forge": "^1.3.3",
85
- "obuild": "^0.4.7",
85
+ "obuild": "^0.4.9",
86
86
  "prettier": "^3.7.4",
87
- "srvx-release": "npm:srvx@^0.9.7",
87
+ "srvx-release": "npm:srvx@^0.9.8",
88
88
  "tslib": "^2.8.1",
89
89
  "typescript": "^5.9.3",
90
90
  "undici": "^7.16.0",
91
- "vitest": "^4.0.15"
91
+ "vitest": "^4.0.16"
92
92
  },
93
- "packageManager": "pnpm@10.25.0",
93
+ "packageManager": "pnpm@10.26.2",
94
94
  "engines": {
95
95
  "node": ">=20.16.0"
96
96
  }