srvx 0.9.5 → 0.9.7

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.
@@ -1,6 +1,6 @@
1
1
  //#region src/_color.ts
2
2
  const noColor = /* @__PURE__ */ (() => {
3
- const env = globalThis.process?.env;
3
+ const env = globalThis.process?.env ?? {};
4
4
  return env.NO_COLOR === "1" || env.TERM === "dumb";
5
5
  })();
6
6
  const _c = (c, r = 39) => (t) => noColor ? t : `\u001B[${c}m${t}\u001B[${r}m`;
@@ -15,4 +15,4 @@ const gray = /* @__PURE__ */ _c(90);
15
15
  const url = (title, url$1) => noColor ? `[${title}](${url$1})` : `\u001B]8;;${url$1}\u001B\\${title}\u001B]8;;\u001B\\`;
16
16
 
17
17
  //#endregion
18
- export { blue, bold, cyan, gray, green, magenta, red, url, yellow };
18
+ export { green as a, url as c, gray as i, yellow as l, bold as n, magenta as o, cyan as r, red as s, blue as t };
@@ -28,4 +28,4 @@ function lazyInherit(target, source, sourceKey) {
28
28
  }
29
29
 
30
30
  //#endregion
31
- export { lazyInherit };
31
+ export { lazyInherit as t };
@@ -1,4 +1,4 @@
1
- import { gray, red } from "./_color-Dtg6hRMg.mjs";
1
+ import { i as gray, s as red } from "./_color-Kmne9cay.mjs";
2
2
 
3
3
  //#region src/_middleware.ts
4
4
  function wrapFetch(server) {
@@ -56,4 +56,4 @@ const gracefulShutdownPlugin = (server) => {
56
56
  };
57
57
 
58
58
  //#endregion
59
- export { errorPlugin, gracefulShutdownPlugin, wrapFetch };
59
+ export { gracefulShutdownPlugin as n, wrapFetch as r, errorPlugin as t };
@@ -25,4 +25,4 @@ declare const FastURL: {
25
25
  };
26
26
  };
27
27
  //#endregion
28
- export { FastURL as FastURL$2 };
28
+ export { FastURL as t };
@@ -1,4 +1,4 @@
1
- import { lazyInherit } from "./_inherit-B9eAGP_O.mjs";
1
+ import { t as lazyInherit } from "./_inherit-D99WuBbX.mjs";
2
2
 
3
3
  //#region src/_url.ts
4
4
  /**
@@ -60,11 +60,10 @@ const FastURL = /* @__PURE__ */ (() => {
60
60
  const url = this.href;
61
61
  const protoIndex = url.indexOf("://");
62
62
  const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
63
- const qIndex = pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex);
64
63
  this.#pos = [
65
64
  protoIndex,
66
65
  pathnameIndex,
67
- qIndex
66
+ pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex)
68
67
  ];
69
68
  }
70
69
  return this.#pos;
@@ -98,8 +97,7 @@ const FastURL = /* @__PURE__ */ (() => {
98
97
  if (this.#protocol === void 0) {
99
98
  const [protocolIndex] = this.#getPos();
100
99
  if (protocolIndex === -1) return this._url.protocol;
101
- const url = this.href;
102
- this.#protocol = url.slice(0, protocolIndex + 1);
100
+ this.#protocol = this.href.slice(0, protocolIndex + 1);
103
101
  }
104
102
  return this.#protocol;
105
103
  }
@@ -117,4 +115,4 @@ const FastURL = /* @__PURE__ */ (() => {
117
115
  })();
118
116
 
119
117
  //#endregion
120
- export { FastURL as FastURL$1 };
118
+ export { FastURL as t };
@@ -3,14 +3,13 @@ function resolvePortAndHost(opts) {
3
3
  const _port = opts.port ?? globalThis.process?.env.PORT ?? 3e3;
4
4
  const port = typeof _port === "number" ? _port : Number.parseInt(_port, 10);
5
5
  if (port < 0 || port > 65535) throw new RangeError(`Port must be between 0 and 65535 (got "${port}").`);
6
- const hostname = opts.hostname ?? globalThis.process?.env.HOST;
7
6
  return {
8
7
  port,
9
- hostname
8
+ hostname: opts.hostname ?? globalThis.process?.env.HOST
10
9
  };
11
10
  }
12
11
  function fmtURL(host, port, secure) {
13
- if (!host || !port) return void 0;
12
+ if (!host || !port) return;
14
13
  if (host.includes(":")) host = `[${host}]`;
15
14
  return `http${secure ? "s" : ""}://${host}:${port}/`;
16
15
  }
@@ -54,7 +53,7 @@ function resolveCertOrKey(value) {
54
53
  return readFileSync(value, "utf8");
55
54
  }
56
55
  function createWaitUntil() {
57
- const promises = new Set();
56
+ const promises = /* @__PURE__ */ new Set();
58
57
  return {
59
58
  waitUntil: (promise) => {
60
59
  if (typeof promise?.then !== "function") return;
@@ -69,4 +68,4 @@ function createWaitUntil() {
69
68
  }
70
69
 
71
70
  //#endregion
72
- export { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions };
71
+ export { resolveTLSOptions as a, resolvePortAndHost as i, fmtURL as n, printListening as r, createWaitUntil as t };
@@ -1,4 +1,4 @@
1
- import { lazyInherit } from "./_inherit-B9eAGP_O.mjs";
1
+ import { t as lazyInherit } from "./_inherit-D99WuBbX.mjs";
2
2
 
3
3
  //#region src/adapters/_node/response.ts
4
4
  /**
@@ -154,4 +154,4 @@ function callNodeHandler(handler, req) {
154
154
  }
155
155
 
156
156
  //#endregion
157
- export { NodeResponse, callNodeHandler };
157
+ export { NodeResponse as n, callNodeHandler as t };
@@ -0,0 +1,4 @@
1
+ import "./_inherit-D99WuBbX.mjs";
2
+ import { t as callNodeHandler } from "./call-BLKVUMn3.mjs";
3
+
4
+ export { callNodeHandler };
@@ -7,13 +7,9 @@ import * as Bun from "bun";
7
7
  import * as CF from "@cloudflare/workers-types";
8
8
 
9
9
  //#region src/types.d.ts
10
- // Utils
11
10
  type MaybePromise<T> = T | Promise<T>;
12
11
  type IsAny<T> = Equal<T, any> extends true ? true : false;
13
12
  type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
14
- // ----------------------------------------------------------------------------
15
- // srvx API
16
- // ----------------------------------------------------------------------------
17
13
  /**
18
14
  * Faster URL constructor with lazy access to pathname and search params (For Node, Deno, and Bun).
19
15
  */
@@ -210,9 +206,6 @@ interface Server<Handler = ServerHandler> {
210
206
  */
211
207
  close(closeActiveConnections?: boolean): Promise<void>;
212
208
  }
213
- // ----------------------------------------------------------------------------
214
- // Request with runtime addons.
215
- // ----------------------------------------------------------------------------
216
209
  interface ServerRuntimeContext {
217
210
  name: "node" | "deno" | "bun" | "cloudflare" | (string & {});
218
211
  /**
@@ -267,9 +260,6 @@ interface ServerRequest extends Request {
267
260
  */
268
261
  waitUntil?: (promise: Promise<unknown>) => void | Promise<void>;
269
262
  }
270
- // ----------------------------------------------------------------------------
271
- // Different handler types
272
- // ----------------------------------------------------------------------------
273
263
  type FetchHandler = (request: Request) => Response | Promise<Response>;
274
264
  type ErrorHandler = (error: unknown) => Response | Promise<Response>;
275
265
  type BunFetchHandler = (request: Request, server?: Bun.Server<any>) => Response | Promise<Response>;
@@ -280,4 +270,4 @@ type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void
280
270
  type NodeHTTPMiddleware = (req: NodeServerRequest, res: NodeServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
281
271
  type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
282
272
  //#endregion
283
- export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve };
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 };
@@ -1,11 +1,10 @@
1
- import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-sQhe-gMy.mjs";
2
- import { FastURL$2 as FastURL } from "../_chunks/_url-Dd8UPFqt.mjs";
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";
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
9
8
  declare class BunServer implements Server<BunFetchHandler> {
10
9
  #private;
11
10
  readonly runtime = "bun";
@@ -1,8 +1,8 @@
1
- import "../_chunks/_color-Dtg6hRMg.mjs";
2
- import "../_chunks/_inherit-B9eAGP_O.mjs";
3
- import { FastURL$1 as FastURL } from "../_chunks/_url-DF-_pEPn.mjs";
4
- import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-DS1d5FUa.mjs";
5
- import { gracefulShutdownPlugin, wrapFetch } from "../_chunks/_plugins-CPeJORNN.mjs";
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";
6
6
 
7
7
  //#region src/adapters/bun.ts
8
8
  const FastResponse = Response;
@@ -1,4 +1,4 @@
1
- import { Server, ServerOptions } from "../_chunks/types-sQhe-gMy.mjs";
1
+ import { f as Server, h as ServerOptions } from "../_chunks/types-CpzLEZLT.mjs";
2
2
  import * as CF from "@cloudflare/workers-types";
3
3
 
4
4
  //#region src/adapters/cloudflare.d.ts
@@ -1,5 +1,5 @@
1
- import "../_chunks/_color-Dtg6hRMg.mjs";
2
- import { errorPlugin, wrapFetch } from "../_chunks/_plugins-CPeJORNN.mjs";
1
+ import "../_chunks/_color-Kmne9cay.mjs";
2
+ import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
3
3
 
4
4
  //#region src/adapters/cloudflare.ts
5
5
  const FastURL = URL;
@@ -1,10 +1,9 @@
1
- import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-sQhe-gMy.mjs";
2
- import { FastURL$2 as FastURL } from "../_chunks/_url-Dd8UPFqt.mjs";
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";
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
8
7
  declare class DenoServer implements Server<DenoFetchHandler> {
9
8
  #private;
10
9
  readonly runtime = "deno";
@@ -1,8 +1,8 @@
1
- import "../_chunks/_color-Dtg6hRMg.mjs";
2
- import "../_chunks/_inherit-B9eAGP_O.mjs";
3
- import { FastURL$1 as FastURL } from "../_chunks/_url-DF-_pEPn.mjs";
4
- import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-DS1d5FUa.mjs";
5
- import { gracefulShutdownPlugin, wrapFetch } from "../_chunks/_plugins-CPeJORNN.mjs";
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";
6
6
 
7
7
  //#region src/adapters/deno.ts
8
8
  const FastResponse = Response;
@@ -1,4 +1,4 @@
1
- import { Server, ServerOptions } from "../_chunks/types-sQhe-gMy.mjs";
1
+ import { f as Server, h as ServerOptions } from "../_chunks/types-CpzLEZLT.mjs";
2
2
 
3
3
  //#region src/adapters/generic.d.ts
4
4
  declare const FastURL: typeof globalThis.URL;
@@ -1,6 +1,6 @@
1
- import "../_chunks/_color-Dtg6hRMg.mjs";
2
- import { createWaitUntil } from "../_chunks/_utils-DS1d5FUa.mjs";
3
- import { errorPlugin, wrapFetch } from "../_chunks/_plugins-CPeJORNN.mjs";
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";
4
4
 
5
5
  //#region src/adapters/generic.ts
6
6
  const FastURL = URL;
@@ -1,5 +1,5 @@
1
- import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-sQhe-gMy.mjs";
2
- import { FastURL$2 as FastURL } from "../_chunks/_url-Dd8UPFqt.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-CpzLEZLT.mjs";
2
+ import { t as FastURL } from "../_chunks/_url-C-JHG430.mjs";
3
3
  import { Readable } from "node:stream";
4
4
 
5
5
  //#region src/adapters/_node/request.d.ts
@@ -12,7 +12,6 @@ declare const NodeRequest: {
12
12
  };
13
13
  //#endregion
14
14
  //#region src/adapters/_node/response.d.ts
15
- // prettier-ignore
16
15
  type PreparedNodeResponseBody = string | Buffer | Uint8Array | DataView | ReadableStream | Readable | undefined | null;
17
16
  interface PreparedNodeResponse {
18
17
  status: number;
@@ -36,9 +35,6 @@ type NodeResponse = InstanceType<typeof NodeResponse>;
36
35
  declare function sendNodeResponse(nodeRes: NodeServerResponse, webRes: Response | NodeResponse): Promise<void>;
37
36
  //#endregion
38
37
  //#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
38
  /**
43
39
  * Calls a Node.js HTTP Request handler with a Fetch API Request object and returns a Response object.
44
40
  *
@@ -71,4 +67,4 @@ declare function toFetchHandler(handler: NodeHttpHandler & AdapterMeta): FetchHa
71
67
  //#region src/adapters/node.d.ts
72
68
  declare function serve(options: ServerOptions): Server;
73
69
  //#endregion
74
- export { NodeResponse as FastResponse, FastURL, NodeRequest, NodeResponse, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
70
+ export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
@@ -1,9 +1,9 @@
1
- import "../_chunks/_color-Dtg6hRMg.mjs";
2
- import { lazyInherit } from "../_chunks/_inherit-B9eAGP_O.mjs";
3
- import { FastURL$1 as FastURL } from "../_chunks/_url-DF-_pEPn.mjs";
4
- import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-DS1d5FUa.mjs";
5
- import { errorPlugin, gracefulShutdownPlugin, wrapFetch } from "../_chunks/_plugins-CPeJORNN.mjs";
6
- import { NodeResponse, callNodeHandler } from "../_chunks/call-BUTAdRs1.mjs";
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";
7
7
  import nodeHTTP, { IncomingMessage, ServerResponse } from "node:http";
8
8
  import { Duplex, Readable } from "node:stream";
9
9
  import nodeHTTPS from "node:https";
@@ -165,11 +165,12 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
165
165
  //#endregion
166
166
  //#region src/adapters/_node/request.ts
167
167
  const NodeRequest = /* @__PURE__ */ (() => {
168
- const NativeRequest = globalThis._Request ??= globalThis.Request;
168
+ const NativeRequest = globalThis[Symbol.for("srvx.nativeRequest")] ??= globalThis.Request;
169
169
  const PatchedRequest = class Request$1 extends NativeRequest {
170
170
  static _srvx = true;
171
171
  static [Symbol.hasInstance](instance) {
172
- return instance instanceof NativeRequest;
172
+ if (this === PatchedRequest) return instance instanceof NativeRequest;
173
+ else return Object.prototype.isPrototypeOf.call(this.prototype, instance);
173
174
  }
174
175
  constructor(input, options) {
175
176
  if (typeof input === "object" && "_request" in input) input = input._request;
@@ -236,8 +237,7 @@ const NodeRequest = /* @__PURE__ */ (() => {
236
237
  if (this.#request) return this.#request.body;
237
238
  if (this.#bodyStream === void 0) {
238
239
  const method = this.method;
239
- const hasBody = !(method === "GET" || method === "HEAD");
240
- this.#bodyStream = hasBody ? Readable.toWeb(this.#req) : null;
240
+ this.#bodyStream = !(method === "GET" || method === "HEAD") ? Readable.toWeb(this.#req) : null;
241
241
  }
242
242
  return this.#bodyStream;
243
243
  }
@@ -486,10 +486,7 @@ var WebServerResponse = class extends ServerResponse {
486
486
  */
487
487
  async function fetchNodeHandler(handler, req) {
488
488
  const nodeRuntime = req.runtime?.node;
489
- if (nodeRuntime && nodeRuntime.req && nodeRuntime.res) {
490
- const webRes = await callNodeHandler(handler, req);
491
- return webRes;
492
- }
489
+ if (nodeRuntime && nodeRuntime.req && nodeRuntime.res) return await callNodeHandler(handler, req);
493
490
  const socket = new WebRequestSocket(req);
494
491
  const nodeReq = new WebIncomingMessage(req, socket);
495
492
  const nodeRes = new WebServerResponse(nodeReq, socket);
@@ -516,11 +513,10 @@ async function fetchNodeHandler(handler, req) {
516
513
  function toNodeHandler(handler) {
517
514
  if (handler.__nodeHandler) return handler.__nodeHandler;
518
515
  function convertedNodeHandler(nodeReq, nodeRes) {
519
- const request = new NodeRequest({
516
+ const res = handler(new NodeRequest({
520
517
  req: nodeReq,
521
518
  res: nodeRes
522
- });
523
- const res = handler(request);
519
+ }));
524
520
  return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
525
521
  }
526
522
  convertedNodeHandler.__fetchHandler = handler;
@@ -595,8 +591,7 @@ var NodeServer = class {
595
591
  };
596
592
  let server;
597
593
  this.#isSecure = !!this.serveOptions.cert && this.options.protocol !== "http";
598
- const isHttp2 = this.options.node?.http2 ?? this.#isSecure;
599
- if (isHttp2) if (this.#isSecure) server = nodeHTTP2.createSecureServer({
594
+ if (this.options.node?.http2 ?? this.#isSecure) if (this.#isSecure) server = nodeHTTP2.createSecureServer({
600
595
  allowHTTP1: true,
601
596
  ...this.serveOptions
602
597
  }, handler);
@@ -637,4 +632,4 @@ var NodeServer = class {
637
632
  };
638
633
 
639
634
  //#endregion
640
- export { NodeResponse as FastResponse, FastURL, NodeRequest, NodeResponse, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
635
+ export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
@@ -1,4 +1,4 @@
1
- import { Server, ServerOptions, ServerRequest } from "../_chunks/types-sQhe-gMy.mjs";
1
+ import { _ as ServerRequest, f as Server, h as ServerOptions } from "../_chunks/types-CpzLEZLT.mjs";
2
2
 
3
3
  //#region src/adapters/service-worker.d.ts
4
4
  declare const FastURL: typeof globalThis.URL;
@@ -1,5 +1,5 @@
1
- import "../_chunks/_color-Dtg6hRMg.mjs";
2
- import { errorPlugin, wrapFetch } from "../_chunks/_plugins-CPeJORNN.mjs";
1
+ import "../_chunks/_color-Kmne9cay.mjs";
2
+ import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
3
3
 
4
4
  //#region src/adapters/service-worker.ts
5
5
  const FastURL = URL;
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { bold, cyan, gray, green, magenta, red, url, yellow } from "./_chunks/_color-Dtg6hRMg.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-Kmne9cay.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";
@@ -81,8 +81,7 @@ async function serve() {
81
81
  try {
82
82
  if (!process.env.NODE_ENV) process.env.NODE_ENV = options._prod ? "production" : "development";
83
83
  const entry = await loadEntry(options);
84
- const forceUseNode = entry._legacyNode;
85
- const { serve: srvxServe } = forceUseNode ? await import("srvx/node") : await import("srvx");
84
+ const { serve: srvxServe } = entry._legacyNode ? await import("srvx/node") : await import("srvx");
86
85
  const { serveStatic } = await import("srvx/static");
87
86
  const { log } = await import("srvx/log");
88
87
  const staticDir = resolve(options._dir, options._static);
@@ -136,7 +135,7 @@ async function loadEntry(opts) {
136
135
  const nodeHandler = listenHandler || (typeof mod.default === "function" ? mod.default : void 0);
137
136
  if (nodeHandler) {
138
137
  _legacyNode = true;
139
- const { callNodeHandler } = await import("./_chunks/call-DdhHMGpi.mjs");
138
+ const { callNodeHandler } = await import("./_chunks/call-BlEaeO5P.mjs");
140
139
  fetchHandler = (webReq) => callNodeHandler(nodeHandler, webReq);
141
140
  }
142
141
  }
@@ -203,8 +202,7 @@ async function interceptListen(cb) {
203
202
  nodeHTTP$1.Server.prototype.listen = originalListen;
204
203
  globalThis.__srvx_listen_cb__ = [arg1, arg2].find((arg) => typeof arg === "function");
205
204
  return new Proxy({}, { get(_, prop) {
206
- const server = globalThis.__srvx__;
207
- return server?.node?.server?.[prop];
205
+ return globalThis.__srvx__?.node?.server?.[prop];
208
206
  } });
209
207
  };
210
208
  res = await cb();
@@ -217,8 +215,7 @@ async function interceptListen(cb) {
217
215
  };
218
216
  }
219
217
  async function version() {
220
- const version$1 = "0.9.4";
221
- return `srvx ${version$1}\n${runtime()}`;
218
+ return `srvx ${globalThis.__srvx_version__ || "unknown"}\n${runtime()}`;
222
219
  }
223
220
  function runtime() {
224
221
  if (process.versions.bun) return `bun ${process.versions.bun}`;
package/dist/log.d.mts CHANGED
@@ -1,7 +1,6 @@
1
- import { ServerMiddleware } from "./_chunks/types-sQhe-gMy.mjs";
1
+ import { m as ServerMiddleware } from "./_chunks/types-CpzLEZLT.mjs";
2
2
 
3
3
  //#region src/log.d.ts
4
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
5
4
  interface LogOptions {}
6
5
  declare const log: (_options?: LogOptions) => ServerMiddleware;
7
6
  //#endregion
package/dist/log.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { blue, bold, gray, green, red, yellow } from "./_chunks/_color-Dtg6hRMg.mjs";
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";
2
2
 
3
3
  //#region src/log.ts
4
4
  const statusColors = {
@@ -12,7 +12,7 @@ const log = (_options = {}) => {
12
12
  const res = await next();
13
13
  const duration = performance.now() - start;
14
14
  const statusColor = statusColors[Math.floor(res.status / 100)] || red;
15
- console.log(`${gray(`[${new Date().toLocaleTimeString()}]`)} ${bold(req.method)} ${blue(req.url)} [${statusColor(res.status + "")}] ${gray(`(${duration.toFixed(2)}ms)`)}`);
15
+ console.log(`${gray(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}]`)} ${bold(req.method)} ${blue(req.url)} [${statusColor(res.status + "")}] ${gray(`(${duration.toFixed(2)}ms)`)}`);
16
16
  return res;
17
17
  };
18
18
  };
package/dist/static.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ServerMiddleware } from "./_chunks/types-sQhe-gMy.mjs";
1
+ import { m as ServerMiddleware } from "./_chunks/types-CpzLEZLT.mjs";
2
2
 
3
3
  //#region src/static.d.ts
4
4
  interface ServeStaticOptions {
package/dist/static.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import "./_chunks/_inherit-B9eAGP_O.mjs";
2
- import { FastURL$1 as FastURL } from "./_chunks/_url-DF-_pEPn.mjs";
1
+ import "./_chunks/_inherit-D99WuBbX.mjs";
2
+ import { t as FastURL } from "./_chunks/_url-COjYRiX5.mjs";
3
3
  import { extname, join, resolve } from "node:path";
4
4
  import { createReadStream } from "node:fs";
5
5
  import { readFile, stat } from "node:fs/promises";
@@ -35,8 +35,7 @@ const serveStatic = (options) => {
35
35
  const methods = new Set((options.methods || ["GET", "HEAD"]).map((m) => m.toUpperCase()));
36
36
  return async (req, next) => {
37
37
  if (!methods.has(req.method)) return next();
38
- const url = req._url ??= new FastURL(req.url);
39
- const path = url.pathname.slice(1).replace(/\/$/, "");
38
+ const path = (req._url ??= new FastURL(req.url)).pathname.slice(1).replace(/\/$/, "");
40
39
  let paths;
41
40
  if (path === "") paths = ["index.html"];
42
41
  else if (extname(path) === "") paths = [`${path}.html`, `${path}/index.html`];
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve } from "./_chunks/types-sQhe-gMy.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-CpzLEZLT.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.5",
3
+ "version": "0.9.7",
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",
@@ -58,38 +58,38 @@
58
58
  "srvx": "link:."
59
59
  },
60
60
  "devDependencies": {
61
- "@cloudflare/workers-types": "^4.20251014.0",
62
- "@hono/node-server": "^1.19.5",
61
+ "@cloudflare/workers-types": "^4.20251128.0",
62
+ "@hono/node-server": "^1.19.6",
63
63
  "@mitata/counters": "^0.0.8",
64
64
  "@mjackson/node-fetch-server": "^0.7.0",
65
- "@types/bun": "^1.3.0",
65
+ "@types/bun": "^1.3.3",
66
66
  "@types/deno": "^2.5.0",
67
- "@types/express": "^5.0.3",
68
- "@types/node": "^24.9.0",
67
+ "@types/express": "^5.0.5",
68
+ "@types/node": "^24.10.1",
69
69
  "@types/node-forge": "^1.3.14",
70
- "@types/serviceworker": "^0.0.158",
71
- "@vitest/coverage-v8": "^3.2.4",
72
- "@whatwg-node/server": "^0.10.13",
70
+ "@types/serviceworker": "^0.0.167",
71
+ "@vitest/coverage-v8": "^4.0.14",
72
+ "@whatwg-node/server": "^0.10.17",
73
73
  "automd": "^0.4.2",
74
74
  "changelogen": "^0.6.2",
75
- "eslint": "^9.38.0",
75
+ "eslint": "^9.39.1",
76
76
  "eslint-config-unjs": "^0.5.0",
77
77
  "execa": "^9.6.0",
78
78
  "express": "^5.1.0",
79
- "fastify": "^5.6.1",
79
+ "fastify": "^5.6.2",
80
80
  "get-port-please": "^3.2.0",
81
81
  "mdbox": "^0.1.1",
82
82
  "mitata": "^1.0.34",
83
- "node-forge": "^1.3.1",
84
- "obuild": "^0.2.1",
85
- "prettier": "^3.6.2",
86
- "srvx-release": "npm:srvx@0.8.16",
83
+ "node-forge": "^1.3.2",
84
+ "obuild": "^0.4.3",
85
+ "prettier": "^3.7.1",
86
+ "srvx-release": "npm:srvx@^0.9.6",
87
87
  "tslib": "^2.8.1",
88
88
  "typescript": "^5.9.3",
89
89
  "undici": "^7.16.0",
90
- "vitest": "^3.2.4"
90
+ "vitest": "4.0.9"
91
91
  },
92
- "packageManager": "pnpm@10.18.3",
92
+ "packageManager": "pnpm@10.24.0",
93
93
  "engines": {
94
94
  "node": ">=20.16.0"
95
95
  }
@@ -1,4 +0,0 @@
1
- import "./_inherit-B9eAGP_O.mjs";
2
- import { callNodeHandler } from "./call-BUTAdRs1.mjs";
3
-
4
- export { callNodeHandler };