srvx 0.9.7 → 0.9.8

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 CHANGED
@@ -60,6 +60,7 @@ $ bunx --bun srvx
60
60
  | `jsx` | [examples/jsx](https://github.com/h3js/srvx/tree/main/examples/jsx/) | `npx giget gh:h3js/srvx/examples/jsx srvx-jsx` |
61
61
  | `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` |
62
62
  | `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` |
63
+ | `tracing` | [examples/tracing](https://github.com/h3js/srvx/tree/main/examples/tracing/) | `npx giget gh:h3js/srvx/examples/tracing srvx-tracing` |
63
64
  | `websocket` | [examples/websocket](https://github.com/h3js/srvx/tree/main/examples/websocket/) | `npx giget gh:h3js/srvx/examples/websocket srvx-websocket` |
64
65
 
65
66
  <!-- /automd -->
@@ -1,4 +1,4 @@
1
- import { i as gray, s as red } from "./_color-Kmne9cay.mjs";
1
+ import { i as gray, s as red } from "./_color.mjs";
2
2
 
3
3
  //#region src/_middleware.ts
4
4
  function wrapFetch(server) {
@@ -1,4 +1,4 @@
1
- import { t as lazyInherit } from "./_inherit-D99WuBbX.mjs";
1
+ import { t as lazyInherit } from "./_inherit.mjs";
2
2
 
3
3
  //#region src/_url.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { t as lazyInherit } from "./_inherit-D99WuBbX.mjs";
1
+ import { t as lazyInherit } from "./_inherit.mjs";
2
2
 
3
3
  //#region src/adapters/_node/response.ts
4
4
  /**
@@ -0,0 +1,3 @@
1
+ import { t as callNodeHandler } from "./call.mjs";
2
+
3
+ export { callNodeHandler };
@@ -1,5 +1,5 @@
1
- import { f as Server, h as ServerOptions, t as BunFetchHandler } from "../_chunks/types-CpzLEZLT.mjs";
2
- import { t as FastURL } from "../_chunks/_url-C-JHG430.mjs";
1
+ import { f as Server, h as ServerOptions, t as BunFetchHandler } from "../_chunks/types.mjs";
2
+ import { t as FastURL } from "../_chunks/_url.mjs";
3
3
  import * as bun from "bun";
4
4
 
5
5
  //#region src/adapters/bun.d.ts
@@ -1,8 +1,6 @@
1
- import "../_chunks/_color-Kmne9cay.mjs";
2
- import "../_chunks/_inherit-D99WuBbX.mjs";
3
- import { t as FastURL } from "../_chunks/_url-COjYRiX5.mjs";
4
- import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils-CIBojyNO.mjs";
5
- import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins-ZJvYKoy9.mjs";
1
+ import { t as FastURL } from "../_chunks/_url.mjs";
2
+ import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils.mjs";
3
+ import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
6
4
 
7
5
  //#region src/adapters/bun.ts
8
6
  const FastResponse = Response;
@@ -1,4 +1,4 @@
1
- import { f as Server, h as ServerOptions } from "../_chunks/types-CpzLEZLT.mjs";
1
+ import { f as Server, h 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,5 +1,4 @@
1
- import "../_chunks/_color-Kmne9cay.mjs";
2
- import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
1
+ import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
3
2
 
4
3
  //#region src/adapters/cloudflare.ts
5
4
  const FastURL = URL;
@@ -1,5 +1,5 @@
1
- import { f as Server, h as ServerOptions, r as DenoFetchHandler } from "../_chunks/types-CpzLEZLT.mjs";
2
- import { t as FastURL } from "../_chunks/_url-C-JHG430.mjs";
1
+ import { f as Server, h as ServerOptions, r as DenoFetchHandler } from "../_chunks/types.mjs";
2
+ import { t as FastURL } from "../_chunks/_url.mjs";
3
3
 
4
4
  //#region src/adapters/deno.d.ts
5
5
  declare const FastResponse: typeof globalThis.Response;
@@ -1,8 +1,6 @@
1
- import "../_chunks/_color-Kmne9cay.mjs";
2
- import "../_chunks/_inherit-D99WuBbX.mjs";
3
- import { t as FastURL } from "../_chunks/_url-COjYRiX5.mjs";
4
- import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils-CIBojyNO.mjs";
5
- import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins-ZJvYKoy9.mjs";
1
+ import { t as FastURL } from "../_chunks/_url.mjs";
2
+ import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils.mjs";
3
+ import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
6
4
 
7
5
  //#region src/adapters/deno.ts
8
6
  const FastResponse = Response;
@@ -1,4 +1,4 @@
1
- import { f as Server, h as ServerOptions } from "../_chunks/types-CpzLEZLT.mjs";
1
+ import { f as Server, h 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,6 +1,5 @@
1
- import "../_chunks/_color-Kmne9cay.mjs";
2
- import { t as createWaitUntil } from "../_chunks/_utils-CIBojyNO.mjs";
3
- import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
1
+ import { t as createWaitUntil } from "../_chunks/_utils.mjs";
2
+ import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
4
3
 
5
4
  //#region src/adapters/generic.ts
6
5
  const FastURL = URL;
@@ -1,5 +1,5 @@
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-CpzLEZLT.mjs";
2
- import { t as FastURL } from "../_chunks/_url-C-JHG430.mjs";
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";
2
+ import { t as FastURL } from "../_chunks/_url.mjs";
3
3
  import { Readable } from "node:stream";
4
4
 
5
5
  //#region src/adapters/_node/request.d.ts
@@ -67,4 +67,4 @@ declare function toFetchHandler(handler: NodeHttpHandler & AdapterMeta): FetchHa
67
67
  //#region src/adapters/node.d.ts
68
68
  declare function serve(options: ServerOptions): Server;
69
69
  //#endregion
70
- export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
70
+ export { type AdapterMeta, NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
@@ -1,9 +1,8 @@
1
- import "../_chunks/_color-Kmne9cay.mjs";
2
- import { t as lazyInherit } from "../_chunks/_inherit-D99WuBbX.mjs";
3
- import { t as FastURL } from "../_chunks/_url-COjYRiX5.mjs";
4
- import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils-CIBojyNO.mjs";
5
- import { n as gracefulShutdownPlugin, r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
6
- import { n as NodeResponse, t as callNodeHandler } from "../_chunks/call-BLKVUMn3.mjs";
1
+ import { t as lazyInherit } from "../_chunks/_inherit.mjs";
2
+ import { t as FastURL } from "../_chunks/_url.mjs";
3
+ import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils.mjs";
4
+ import { n as gracefulShutdownPlugin, r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
5
+ import { n as NodeResponse, t as callNodeHandler } from "../_chunks/call.mjs";
7
6
  import nodeHTTP, { IncomingMessage, ServerResponse } from "node:http";
8
7
  import { Duplex, Readable } from "node:stream";
9
8
  import nodeHTTPS from "node:https";
@@ -221,12 +220,18 @@ const NodeRequest = /* @__PURE__ */ (() => {
221
220
  get _abortController() {
222
221
  if (!this.#abortController) {
223
222
  this.#abortController = new AbortController();
224
- const req = this.#req;
225
- const abort = (err) => {
226
- this.#abortController?.abort?.(err);
227
- };
223
+ const { req, res } = this.runtime.node;
224
+ const abortController = this.#abortController;
225
+ const abort = (err) => abortController.abort?.(err);
228
226
  req.once("error", abort);
229
- req.once("end", abort);
227
+ if (res) res.once("close", () => {
228
+ const reqError = req.errored;
229
+ if (reqError) abort(reqError);
230
+ else if (!res.writableEnded) abort();
231
+ });
232
+ else req.once("close", () => {
233
+ if (!req.complete) abort();
234
+ });
230
235
  }
231
236
  return this.#abortController;
232
237
  }
@@ -1,4 +1,4 @@
1
- import { _ as ServerRequest, f as Server, h as ServerOptions } from "../_chunks/types-CpzLEZLT.mjs";
1
+ import { _ as ServerRequest, f as Server, h 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;
@@ -1,5 +1,4 @@
1
- import "../_chunks/_color-Kmne9cay.mjs";
2
- import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
1
+ import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
3
2
 
4
3
  //#region src/adapters/service-worker.ts
5
4
  const FastURL = URL;
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as green, c as url, i as gray, l as yellow, n as bold, o as magenta, r as cyan, s as red } from "./_chunks/_color-Kmne9cay.mjs";
1
+ import { a as green, c as url, i as gray, l as yellow, n as bold, o as magenta, r as cyan, s as red } from "./_chunks/_color.mjs";
2
2
  import { parseArgs } from "node:util";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import * as nodeHTTP$1 from "node:http";
@@ -135,7 +135,7 @@ async function loadEntry(opts) {
135
135
  const nodeHandler = listenHandler || (typeof mod.default === "function" ? mod.default : void 0);
136
136
  if (nodeHandler) {
137
137
  _legacyNode = true;
138
- const { callNodeHandler } = await import("./_chunks/call-BlEaeO5P.mjs");
138
+ const { callNodeHandler } = await import("./_chunks/call2.mjs");
139
139
  fetchHandler = (webReq) => callNodeHandler(nodeHandler, webReq);
140
140
  }
141
141
  }
package/dist/log.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { m as ServerMiddleware } from "./_chunks/types-CpzLEZLT.mjs";
1
+ import { m as ServerMiddleware } from "./_chunks/types.mjs";
2
2
 
3
3
  //#region src/log.d.ts
4
4
  interface LogOptions {}
package/dist/log.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as green, i as gray, l as yellow, n as bold, s as red, t as blue } from "./_chunks/_color-Kmne9cay.mjs";
1
+ import { a as green, i as gray, l as yellow, n as bold, s as red, t as blue } from "./_chunks/_color.mjs";
2
2
 
3
3
  //#region src/log.ts
4
4
  const statusColors = {
package/dist/static.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { m as ServerMiddleware } from "./_chunks/types-CpzLEZLT.mjs";
1
+ import { m as ServerMiddleware } from "./_chunks/types.mjs";
2
2
 
3
3
  //#region src/static.d.ts
4
4
  interface ServeStaticOptions {
package/dist/static.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import "./_chunks/_inherit-D99WuBbX.mjs";
2
- import { t as FastURL } from "./_chunks/_url-COjYRiX5.mjs";
1
+ import { t as FastURL } from "./_chunks/_url.mjs";
3
2
  import { extname, join, resolve } from "node:path";
4
3
  import { createReadStream } from "node:fs";
5
4
  import { readFile, stat } from "node:fs/promises";
@@ -0,0 +1,42 @@
1
+ import { _ as ServerRequest, f as Server, g as ServerPlugin, m as ServerMiddleware } from "./_chunks/types.mjs";
2
+
3
+ //#region src/tracing.d.ts
4
+
5
+ /**
6
+ * @experimental Channel names, event types and config options may change in future releases.
7
+ */
8
+ type RequestEvent = {
9
+ server: Server;
10
+ request: ServerRequest;
11
+ middleware?: {
12
+ index: number;
13
+ handler: ServerMiddleware;
14
+ };
15
+ };
16
+ /**
17
+ *
18
+ * @experimental Channel names, event types and config options may change in future releases.
19
+ *
20
+ * Tracing plugin that adds diagnostics channel tracing to middleware and fetch handlers.
21
+ *
22
+ * This plugin wraps all middleware and the fetch handler with tracing instrumentation,
23
+ * allowing you to subscribe to `srvx.fetch` and `srvx.middleware` tracing channels.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { serve } from "srvx";
28
+ * import { tracingPlugin } from "srvx/tracing";
29
+ *
30
+ * const server = serve({
31
+ * fetch: (req) => new Response("OK"),
32
+ * middleware: [myMiddleware],
33
+ * plugins: [tracingPlugin()],
34
+ * });
35
+ * ```
36
+ */
37
+ declare function tracingPlugin(opts?: {
38
+ middleware?: boolean;
39
+ fetch?: boolean;
40
+ }): ServerPlugin;
41
+ //#endregion
42
+ export { RequestEvent, tracingPlugin };
@@ -0,0 +1,58 @@
1
+ //#region src/tracing.ts
2
+ /**
3
+ *
4
+ * @experimental Channel names, event types and config options may change in future releases.
5
+ *
6
+ * Tracing plugin that adds diagnostics channel tracing to middleware and fetch handlers.
7
+ *
8
+ * This plugin wraps all middleware and the fetch handler with tracing instrumentation,
9
+ * allowing you to subscribe to `srvx.fetch` and `srvx.middleware` tracing channels.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { serve } from "srvx";
14
+ * import { tracingPlugin } from "srvx/tracing";
15
+ *
16
+ * const server = serve({
17
+ * fetch: (req) => new Response("OK"),
18
+ * middleware: [myMiddleware],
19
+ * plugins: [tracingPlugin()],
20
+ * });
21
+ * ```
22
+ */
23
+ function tracingPlugin(opts = {}) {
24
+ return (server) => {
25
+ const { tracingChannel } = globalThis.process?.getBuiltinModule?.("node:diagnostics_channel") || {};
26
+ if (!tracingChannel) return;
27
+ if (opts.fetch !== false) {
28
+ const fetchChannel = tracingChannel("srvx.fetch");
29
+ const originalFetch = server.options.fetch;
30
+ server.options.fetch = (request) => {
31
+ return fetchChannel.tracePromise(async () => await originalFetch(request), {
32
+ request,
33
+ server
34
+ });
35
+ };
36
+ }
37
+ if (opts.middleware !== false) {
38
+ const middlewareChannel = tracingChannel("srvx.middleware");
39
+ const wrappedMiddleware = server.options.middleware.map((handler, index) => {
40
+ const middleware = Object.freeze({
41
+ index,
42
+ handler
43
+ });
44
+ return (request, next) => {
45
+ return middlewareChannel.tracePromise(async () => await handler(request, next), {
46
+ request,
47
+ server,
48
+ middleware
49
+ });
50
+ };
51
+ });
52
+ server.options.middleware.splice(0, server.options.middleware.length, ...wrappedMiddleware);
53
+ }
54
+ };
55
+ }
56
+
57
+ //#endregion
58
+ export { tracingPlugin };
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-CpzLEZLT.mjs";
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
2
  export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, 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.7",
3
+ "version": "0.9.8",
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",
@@ -17,6 +17,7 @@
17
17
  "./cli": "./dist/cli.mjs",
18
18
  "./static": "./dist/static.mjs",
19
19
  "./log": "./dist/log.mjs",
20
+ "./tracing": "./dist/tracing.mjs",
20
21
  ".": {
21
22
  "types": "./dist/types.d.mts",
22
23
  "deno": "./dist/adapters/deno.mjs",
@@ -58,38 +59,38 @@
58
59
  "srvx": "link:."
59
60
  },
60
61
  "devDependencies": {
61
- "@cloudflare/workers-types": "^4.20251128.0",
62
- "@hono/node-server": "^1.19.6",
62
+ "@cloudflare/workers-types": "^4.20251210.0",
63
+ "@hono/node-server": "^1.19.7",
63
64
  "@mitata/counters": "^0.0.8",
64
65
  "@mjackson/node-fetch-server": "^0.7.0",
65
- "@types/bun": "^1.3.3",
66
+ "@types/bun": "^1.3.4",
66
67
  "@types/deno": "^2.5.0",
67
- "@types/express": "^5.0.5",
68
- "@types/node": "^24.10.1",
68
+ "@types/express": "^5.0.6",
69
+ "@types/node": "^25.0.0",
69
70
  "@types/node-forge": "^1.3.14",
70
- "@types/serviceworker": "^0.0.167",
71
- "@vitest/coverage-v8": "^4.0.14",
71
+ "@types/serviceworker": "^0.0.168",
72
+ "@vitest/coverage-v8": "^4.0.15",
72
73
  "@whatwg-node/server": "^0.10.17",
73
74
  "automd": "^0.4.2",
74
75
  "changelogen": "^0.6.2",
75
76
  "eslint": "^9.39.1",
76
77
  "eslint-config-unjs": "^0.5.0",
77
- "execa": "^9.6.0",
78
- "express": "^5.1.0",
78
+ "execa": "^9.6.1",
79
+ "express": "^5.2.1",
79
80
  "fastify": "^5.6.2",
80
81
  "get-port-please": "^3.2.0",
81
82
  "mdbox": "^0.1.1",
82
83
  "mitata": "^1.0.34",
83
- "node-forge": "^1.3.2",
84
- "obuild": "^0.4.3",
85
- "prettier": "^3.7.1",
86
- "srvx-release": "npm:srvx@^0.9.6",
84
+ "node-forge": "^1.3.3",
85
+ "obuild": "^0.4.7",
86
+ "prettier": "^3.7.4",
87
+ "srvx-release": "npm:srvx@^0.9.7",
87
88
  "tslib": "^2.8.1",
88
89
  "typescript": "^5.9.3",
89
90
  "undici": "^7.16.0",
90
- "vitest": "4.0.9"
91
+ "vitest": "^4.0.15"
91
92
  },
92
- "packageManager": "pnpm@10.24.0",
93
+ "packageManager": "pnpm@10.25.0",
93
94
  "engines": {
94
95
  "node": ">=20.16.0"
95
96
  }
@@ -1,4 +0,0 @@
1
- import "./_inherit-D99WuBbX.mjs";
2
- import { t as callNodeHandler } from "./call-BLKVUMn3.mjs";
3
-
4
- export { callNodeHandler };