srvx 0.7.1 → 0.7.2

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.
@@ -89,11 +89,7 @@ const FastURL = /* @__PURE__ */ (() => {
89
89
  const url = this.#originalURL;
90
90
  const protoIndex = url.indexOf("://");
91
91
  if (protoIndex === -1) return this._url.pathname;
92
- const pIndex = url.indexOf(
93
- "/",
94
- protoIndex + 4
95
- /* :// */
96
- );
92
+ const pIndex = url.indexOf("/", protoIndex + 4);
97
93
  if (pIndex === -1) return this._url.pathname;
98
94
  const qIndex = this._urlqindex = url.indexOf("?", pIndex);
99
95
  this._pathname = url.slice(pIndex, qIndex === -1 ? void 0 : qIndex);
@@ -7,6 +7,9 @@ import * as CF from "@cloudflare/workers-types";
7
7
 
8
8
  //#region src/types.d.ts
9
9
  type MaybePromise<T> = T | Promise<T>;
10
+ // ----------------------------------------------------------------------------
11
+ // srvx API
12
+ // ----------------------------------------------------------------------------
10
13
  /**
11
14
  * Faster URL constructor with lazy access to pathname and search params (For Node, Deno, and Bun).
12
15
  */
@@ -187,6 +190,9 @@ interface Server<Handler = ServerHandler> {
187
190
  */
188
191
  close(closeActiveConnections?: boolean): Promise<void>;
189
192
  }
193
+ // ----------------------------------------------------------------------------
194
+ // Request with runtime addons.
195
+ // ----------------------------------------------------------------------------
190
196
  interface ServerRuntimeContext {
191
197
  name: "node" | "deno" | "bun" | "cloudflare" | (string & {});
192
198
  /**
@@ -226,6 +232,9 @@ interface ServerRequest extends Request {
226
232
  */
227
233
  ip?: string | undefined;
228
234
  }
235
+ // ----------------------------------------------------------------------------
236
+ // Different handler types
237
+ // ----------------------------------------------------------------------------
229
238
  type FetchHandler = (request: Request) => Response | Promise<Response>;
230
239
  type ErrorHandler = (error: unknown) => Response | Promise<Response>;
231
240
  type BunFetchHandler = (request: Request, server?: Bun.Server) => Response | Promise<Response>;
@@ -233,5 +242,6 @@ type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.Net
233
242
  type NodeServerRequest = NodeHttp$1.IncomingMessage | NodeHttp2.Http2ServerRequest;
234
243
  type NodeServerResponse = NodeHttp$1.ServerResponse | NodeHttp2.Http2ServerResponse;
235
244
  type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
236
- type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler; //#endregion
245
+ type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
246
+ //#endregion
237
247
  export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve };
@@ -1,10 +1,11 @@
1
- import { BunFetchHandler, Server, ServerOptions } from "./chunks/types-egi3HKdd.mjs";
2
- import { FastURL$2 as FastURL } from "./chunks/_url-BwTFuoNW.mjs";
1
+ import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
2
+ import { FastURL$2 as FastURL } from "../_chunks/_url-0kFTYgtJ.mjs";
3
3
  import * as bun from "bun";
4
4
 
5
5
  //#region src/adapters/bun.d.ts
6
6
  declare const FastResponse: typeof globalThis.Response;
7
7
  declare function serve(options: ServerOptions): BunServer;
8
+ // https://bun.sh/docs/api/http
8
9
  declare class BunServer implements Server<BunFetchHandler> {
9
10
  readonly runtime = "bun";
10
11
  readonly options: Server["options"];
@@ -17,6 +18,5 @@ declare class BunServer implements Server<BunFetchHandler> {
17
18
  ready(): Promise<this>;
18
19
  close(closeAll?: boolean): Promise<void>;
19
20
  }
20
-
21
21
  //#endregion
22
22
  export { FastResponse, FastURL, serve };
@@ -1,5 +1,5 @@
1
- import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "./chunks/_url-CirWh9Lc.mjs";
2
- import { wrapFetch } from "./chunks/_middleware-DSFIayTI.mjs";
1
+ import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_url-Dsik4Hgl.mjs";
2
+ import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
3
3
 
4
4
  //#region src/adapters/bun.ts
5
5
  const FastResponse = Response;
@@ -24,7 +24,7 @@ var BunServer = class {
24
24
  runtime: {
25
25
  enumerable: true,
26
26
  value: {
27
- runtime: "bun",
27
+ name: "bun",
28
28
  bun: { server }
29
29
  }
30
30
  },
@@ -1,10 +1,9 @@
1
- import { Server, ServerOptions } from "./chunks/types-egi3HKdd.mjs";
1
+ import { Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
2
2
  import * as CF from "@cloudflare/workers-types";
3
3
 
4
4
  //#region src/adapters/cloudflare.d.ts
5
5
  declare const FastURL: typeof globalThis.URL;
6
6
  declare const FastResponse: typeof globalThis.Response;
7
7
  declare function serve(options: ServerOptions): Server<CF.ExportedHandlerFetchHandler>;
8
-
9
8
  //#endregion
10
9
  export { FastResponse, FastURL, serve };
@@ -1,5 +1,5 @@
1
- import { wrapFetch } from "./chunks/_middleware-DSFIayTI.mjs";
2
- import { errorPlugin } from "./chunks/_plugins-BTotWVHV.mjs";
1
+ import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
2
+ import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
3
3
 
4
4
  //#region src/adapters/cloudflare.ts
5
5
  const FastURL = URL;
@@ -24,7 +24,7 @@ var CloudflareServer = class {
24
24
  Object.defineProperties(request, { runtime: {
25
25
  enumerable: true,
26
26
  value: {
27
- runtime: "cloudflare",
27
+ name: "cloudflare",
28
28
  cloudflare: {
29
29
  env,
30
30
  context
@@ -1,9 +1,10 @@
1
- import { DenoFetchHandler, Server, ServerOptions } from "./chunks/types-egi3HKdd.mjs";
2
- import { FastURL$2 as FastURL } from "./chunks/_url-BwTFuoNW.mjs";
1
+ import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
2
+ import { FastURL$2 as FastURL } from "../_chunks/_url-0kFTYgtJ.mjs";
3
3
 
4
4
  //#region src/adapters/deno.d.ts
5
5
  declare const FastResponse: typeof globalThis.Response;
6
6
  declare function serve(options: ServerOptions): DenoServer;
7
+ // https://docs.deno.com/api/deno/~/Deno.serve
7
8
  declare class DenoServer implements Server<DenoFetchHandler> {
8
9
  #private;
9
10
  readonly runtime = "deno";
@@ -17,6 +18,5 @@ declare class DenoServer implements Server<DenoFetchHandler> {
17
18
  ready(): Promise<Server>;
18
19
  close(): Promise<void | undefined>;
19
20
  }
20
-
21
21
  //#endregion
22
22
  export { FastResponse, FastURL, serve };
@@ -1,5 +1,5 @@
1
- import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "./chunks/_url-CirWh9Lc.mjs";
2
- import { wrapFetch } from "./chunks/_middleware-DSFIayTI.mjs";
1
+ import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_url-Dsik4Hgl.mjs";
2
+ import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
3
3
 
4
4
  //#region src/adapters/deno.ts
5
5
  const FastResponse = Response;
@@ -26,7 +26,7 @@ var DenoServer = class {
26
26
  runtime: {
27
27
  enumerable: true,
28
28
  value: {
29
- runtime: "deno",
29
+ name: "deno",
30
30
  deno: {
31
31
  info,
32
32
  server: this.deno?.server
@@ -1,9 +1,8 @@
1
- import { Server, ServerOptions } from "./chunks/types-egi3HKdd.mjs";
1
+ import { Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
2
2
 
3
3
  //#region src/adapters/generic.d.ts
4
4
  declare const FastURL: typeof globalThis.URL;
5
5
  declare const FastResponse: typeof globalThis.Response;
6
6
  declare function serve(options: ServerOptions): Server;
7
-
8
7
  //#endregion
9
8
  export { FastResponse, FastURL, serve };
@@ -1,5 +1,5 @@
1
- import { wrapFetch } from "./chunks/_middleware-DSFIayTI.mjs";
2
- import { errorPlugin } from "./chunks/_plugins-BTotWVHV.mjs";
1
+ import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
2
+ import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
3
3
 
4
4
  //#region src/adapters/generic.ts
5
5
  const FastURL = URL;
@@ -1,5 +1,5 @@
1
- import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "./chunks/types-egi3HKdd.mjs";
2
- import { FastURL$2 as FastURL } from "./chunks/_url-BwTFuoNW.mjs";
1
+ import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-CAoaOHnD.mjs";
2
+ import { FastURL$2 as FastURL } from "../_chunks/_url-0kFTYgtJ.mjs";
3
3
  import NodeHttp from "node:http";
4
4
  import { Readable } from "node:stream";
5
5
 
@@ -11,7 +11,6 @@ type NodeRequestContext = {
11
11
  declare const NodeRequest: {
12
12
  new (nodeCtx: NodeRequestContext): ServerRequest;
13
13
  };
14
-
15
14
  //#endregion
16
15
  //#region src/adapters/_node/headers.d.ts
17
16
  declare const NodeRequestHeaders: {
@@ -26,7 +25,6 @@ declare const NodeResponseHeaders: {
26
25
  res: NodeServerResponse;
27
26
  }): globalThis.Headers;
28
27
  };
29
-
30
28
  //#endregion
31
29
  //#region src/adapters/_node/response.d.ts
32
30
  type NodeResponse = InstanceType<typeof NodeResponse>;
@@ -45,11 +43,9 @@ declare const NodeResponse: {
45
43
  };
46
44
  };
47
45
  };
48
-
49
46
  //#endregion
50
47
  //#region src/adapters/node.d.ts
51
48
  declare function serve(options: ServerOptions): Server;
52
49
  declare function toNodeHandler(fetchHandler: FetchHandler): NodeHttpHandler;
53
-
54
50
  //#endregion
55
51
  export { NodeResponse as FastResponse, FastURL, NodeRequest, NodeRequestHeaders, NodeResponse, NodeResponseHeaders, serve, toNodeHandler };
@@ -1,6 +1,6 @@
1
- import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "./chunks/_url-CirWh9Lc.mjs";
2
- import { wrapFetch } from "./chunks/_middleware-DSFIayTI.mjs";
3
- import { errorPlugin } from "./chunks/_plugins-BTotWVHV.mjs";
1
+ import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_url-Dsik4Hgl.mjs";
2
+ import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
3
+ import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
4
4
  import { splitSetCookieString } from "cookie-es";
5
5
 
6
6
  //#region src/adapters/_node/send.ts
@@ -426,7 +426,12 @@ const NodeRequest = /* @__PURE__ */ (() => {
426
426
  return this._node.req.method || "GET";
427
427
  }
428
428
  get signal() {
429
- if (!this.#abortSignal) this.#abortSignal = new AbortController();
429
+ if (!this.#abortSignal) {
430
+ this.#abortSignal = new AbortController();
431
+ this._node.req.once("close", () => {
432
+ this.#abortSignal?.abort();
433
+ });
434
+ }
430
435
  return this.#abortSignal.signal;
431
436
  }
432
437
  get bodyUsed() {
@@ -1,10 +1,9 @@
1
- import { Server, ServerOptions, ServerRequest } from "./chunks/types-egi3HKdd.mjs";
1
+ import { Server, ServerOptions, ServerRequest } from "../_chunks/types-CAoaOHnD.mjs";
2
2
 
3
3
  //#region src/adapters/service-worker.d.ts
4
4
  declare const FastURL: typeof globalThis.URL;
5
5
  declare const FastResponse: typeof globalThis.Response;
6
6
  type ServiceWorkerHandler = (request: ServerRequest, event: FetchEvent) => Response | Promise<Response>;
7
7
  declare function serve(options: ServerOptions): Server<ServiceWorkerHandler>;
8
-
9
8
  //#endregion
10
9
  export { FastResponse, FastURL, ServiceWorkerHandler, serve };
@@ -1,5 +1,5 @@
1
- import { wrapFetch } from "./chunks/_middleware-DSFIayTI.mjs";
2
- import { errorPlugin } from "./chunks/_plugins-BTotWVHV.mjs";
1
+ import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
2
+ import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
3
3
 
4
4
  //#region src/adapters/service-worker.ts
5
5
  const FastURL = URL;
@@ -27,7 +27,7 @@ var ServiceWorkerServer = class {
27
27
  Object.defineProperties(request, { runtime: {
28
28
  enumerable: true,
29
29
  value: {
30
- runtime: "service-worker",
30
+ name: "service-worker",
31
31
  serviceWorker: { event }
32
32
  }
33
33
  } });
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve } from "./chunks/types-egi3HKdd.mjs";
1
+ import { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve } from "./_chunks/types-CAoaOHnD.mjs";
2
2
  export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "srvx",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
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",
@@ -9,20 +9,20 @@
9
9
  "type": "module",
10
10
  "exports": {
11
11
  "./types": "./dist/types.d.mts",
12
- "./deno": "./dist/deno.mjs",
13
- "./bun": "./dist/bun.mjs",
14
- "./node": "./dist/node.mjs",
15
- "./cloudflare": "./dist/cloudflare.mjs",
16
- "./generic": "./dist/generic.mjs",
17
- "./service-worker": "./dist/service-worker.mjs",
12
+ "./deno": "./dist/adapters/deno.mjs",
13
+ "./bun": "./dist/adapters/bun.mjs",
14
+ "./node": "./dist/adapters/node.mjs",
15
+ "./cloudflare": "./dist/adapters/cloudflare.mjs",
16
+ "./generic": "./dist/adapters/generic.mjs",
17
+ "./service-worker": "./dist/adapters/service-worker.mjs",
18
18
  ".": {
19
19
  "types": "./dist/types.d.mts",
20
- "deno": "./dist/deno.mjs",
21
- "bun": "./dist/bun.mjs",
22
- "workerd": "./dist/cloudflare.mjs",
23
- "browser": "./dist/service-worker.mjs",
24
- "node": "./dist/node.mjs",
25
- "default": "./dist/generic.mjs"
20
+ "deno": "./dist/adapters/deno.mjs",
21
+ "bun": "./dist/adapters/bun.mjs",
22
+ "workerd": "./dist/adapters/cloudflare.mjs",
23
+ "browser": "./dist/adapters/service-worker.mjs",
24
+ "node": "./dist/adapters/node.mjs",
25
+ "default": "./dist/adapters/generic.mjs"
26
26
  }
27
27
  },
28
28
  "types": "./dist/types.d.mts",
@@ -44,7 +44,7 @@
44
44
  "play:cf": "pnpx wrangler dev playground/app.mjs",
45
45
  "play:deno": "deno run -A playground/app.mjs",
46
46
  "play:mkcert": "openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt -days 365 -subj /CN=srvx.local",
47
- "play:node": "node playground/app.mjs",
47
+ "play:node": "pnpm node-ts playground/app.mjs",
48
48
  "play:sw": "pnpm build && pnpx serve playground",
49
49
  "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
50
50
  "test": "pnpm lint && pnpm test:types && vitest run --coverage",
@@ -57,29 +57,31 @@
57
57
  "cookie-es": "^2.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@cloudflare/workers-types": "^4.20250513.0",
61
- "@hono/node-server": "^1.14.1",
60
+ "@cloudflare/workers-types": "^4.20250525.0",
61
+ "@hono/node-server": "^1.14.3",
62
62
  "@mitata/counters": "^0.0.8",
63
63
  "@mjackson/node-fetch-server": "^0.6.1",
64
- "@types/bun": "^1.2.13",
64
+ "@types/bun": "^1.2.14",
65
65
  "@types/deno": "^2.3.0",
66
- "@types/node": "^22.15.17",
66
+ "@types/node": "^22.15.21",
67
67
  "@types/node-forge": "^1.3.11",
68
- "@types/serviceworker": "^0.0.134",
69
- "@vitest/coverage-v8": "^3.1.3",
68
+ "@types/serviceworker": "^0.0.135",
69
+ "@vitest/coverage-v8": "^3.1.4",
70
+ "@whatwg-node/server": "^0.10.10",
70
71
  "automd": "^0.4.0",
71
72
  "changelogen": "^0.6.1",
72
- "eslint": "^9.26.0",
73
+ "eslint": "^9.27.0",
73
74
  "eslint-config-unjs": "^0.4.2",
74
- "execa": "^9.5.3",
75
+ "execa": "^9.6.0",
75
76
  "get-port-please": "^3.1.2",
76
77
  "mitata": "^1.0.34",
77
78
  "node-forge": "^1.3.1",
78
- "obuild": "^0.0.7",
79
+ "obuild": "^0.2.0",
79
80
  "prettier": "^3.5.3",
81
+ "tslib": "^2.8.1",
80
82
  "typescript": "^5.8.3",
81
- "undici": "^7.9.0",
82
- "vitest": "^3.1.3"
83
+ "undici": "^7.10.0",
84
+ "vitest": "^3.1.4"
83
85
  },
84
86
  "packageManager": "pnpm@10.11.0",
85
87
  "engines": {