🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

srvx

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

srvx - npm Package Compare versions

Comparing version
0.11.16
to
0.11.17
+2
-2
dist/_chunks/_plugins.mjs

@@ -1,2 +0,2 @@

import { a as green, i as gray, n as bold, s as red } from "./_utils.mjs";
import { bold, gray, green, red } from "./_utils.mjs";
function wrapFetch(server) {

@@ -56,2 +56,2 @@ const fetchHandler = server.options.fetch;

};
export { gracefulShutdownPlugin as n, wrapFetch as r, errorPlugin as t };
export { errorPlugin, gracefulShutdownPlugin, wrapFetch };

@@ -17,3 +17,3 @@ type URLInit = {

*
* - It is assumed that the input URL is **already encoded** and formatted from an HTTP request and contains no hash.
* - It is assumed that the input URL is **already encoded** and formatted from an HTTP request. A fragment (`#`), while not valid in an origin-form request target, is handled via full URL parsing.
* - Triggering the setters or getters on other props will deoptimize to full URL parsing.

@@ -27,2 +27,2 @@ * - Changes to `searchParams` will be discarded as we don't track them.

};
export { FastURL as t };
export { FastURL };

@@ -28,3 +28,3 @@ function lazyInherit(target, source, sourceKey) {

}
const _needsNormRE = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^\x80-\uffff]/i;
const _needsNormRE = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^#"<>{}`\x80-\uffff]/i;
const FastURL = /* @__PURE__ */ (() => {

@@ -42,5 +42,7 @@ const NativeURL = globalThis.URL;

constructor(url) {
if (typeof url === "string") if (url[0] === "/") this.#href = url;
else this.#url = new NativeURL(url);
else if (_needsNormRE.test(url.pathname)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
if (typeof url === "string") {
const isOriginForm = url[0] === "/";
if (isOriginForm && !url.includes("#")) this.#href = url;
else this.#url = new NativeURL(isOriginForm ? `http://localhost${url}` : url);
} else if (_needsNormRE.test(url.pathname) || url.search?.includes("#")) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
else {

@@ -133,2 +135,2 @@ this.#protocol = url.protocol;

})();
export { lazyInherit as n, FastURL as t };
export { FastURL, lazyInherit };

@@ -15,2 +15,2 @@ const noColor = /* @__PURE__ */ (() => {

const url = (title, url) => noColor ? `[${title}](${url})` : `\u001B]8;;${url}\u001B\\${title}\u001B]8;;\u001B\\`;
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 };
export { blue, bold, cyan, gray, green, magenta, red, url, yellow };

@@ -70,2 +70,2 @@ function resolvePortAndHost(opts) {

}
export { resolveTLSOptions as a, resolvePortAndHost as i, fmtURL as n, printListening as r, createWaitUntil as t };
export { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions };

@@ -84,2 +84,2 @@ import { Server, ServerHandler } from "srvx";

type NodeServer = NonNullable<Server["node"]>["server"];
export { loadServerEntry as a, defaultExts as i, LoadedServerEntry as n, defaultEntries as r, LoadOptions as t };
export { LoadOptions, LoadedServerEntry, defaultEntries, defaultExts, loadServerEntry };

@@ -1,2 +0,2 @@

import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
import { errorPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
function awsRequest(event, context) {

@@ -3,0 +3,0 @@ const req = new Request(awsEventURL(event), {

import { BunFetchHandler, Server, ServerOptions } from "../types.mjs";
import { t as FastURL } from "../_chunks/_url.mjs";
import { FastURL } from "../_chunks/_url.mjs";
import * as bun from "bun";

@@ -4,0 +4,0 @@ declare const FastResponse: typeof globalThis.Response;

@@ -1,4 +0,4 @@

import { t as FastURL } from "../_chunks/_url.mjs";
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils2.mjs";
import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
import { FastURL } from "../_chunks/_url.mjs";
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils2.mjs";
import { gracefulShutdownPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
const FastResponse = Response;

@@ -5,0 +5,0 @@ function serve(options) {

@@ -1,2 +0,2 @@

import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
import { errorPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
const FastURL = URL;

@@ -3,0 +3,0 @@ const FastResponse = Response;

@@ -1,2 +0,2 @@

import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
import { errorPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
const FastURL = URL;

@@ -3,0 +3,0 @@ const FastResponse = Response;

import { DenoFetchHandler, Server, ServerOptions } from "../types.mjs";
import { t as FastURL } from "../_chunks/_url.mjs";
import { FastURL } from "../_chunks/_url.mjs";
declare const FastResponse: typeof globalThis.Response;

@@ -4,0 +4,0 @@ declare function serve(options: ServerOptions): DenoServer;

@@ -1,4 +0,4 @@

import { t as FastURL } from "../_chunks/_url.mjs";
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils2.mjs";
import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
import { FastURL } from "../_chunks/_url.mjs";
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils2.mjs";
import { gracefulShutdownPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
const FastResponse = Response;

@@ -5,0 +5,0 @@ function serve(options) {

@@ -1,3 +0,3 @@

import { t as createWaitUntil } from "../_chunks/_utils2.mjs";
import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
import { createWaitUntil } from "../_chunks/_utils2.mjs";
import { errorPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
const FastURL = URL;

@@ -4,0 +4,0 @@ const FastResponse = Response;

import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../types.mjs";
import { t as FastURL } from "../_chunks/_url.mjs";
import { FastURL } from "../_chunks/_url.mjs";
import { Readable } from "node:stream";

@@ -65,2 +65,2 @@ type NodeRequestContext = {

declare function serve(options: ServerOptions): Server;
export { type AdapterMeta, NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
export { type AdapterMeta, NodeResponse as FastResponse, FastURL, NodeRequest, NodeResponse, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };

@@ -1,6 +0,6 @@

import { n as lazyInherit, t as FastURL } from "../_chunks/_url.mjs";
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils2.mjs";
import { n as gracefulShutdownPlugin, r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
import { FastURL, lazyInherit } from "../_chunks/_url.mjs";
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils2.mjs";
import { errorPlugin, gracefulShutdownPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
import nodeHTTP, { IncomingMessage, ServerResponse } from "node:http";
import { Duplex, PassThrough, Readable } from "node:stream";
import { Duplex, PassThrough, Readable, addAbortSignal } from "node:stream";
import { pipeline } from "node:stream/promises";

@@ -186,4 +186,5 @@ import nodeHTTPS from "node:https";

})();
const kNativeRequest = /* @__PURE__ */ Symbol.for("srvx.nativeRequest");
const NodeRequest = /* @__PURE__ */ (() => {
const NativeRequest = globalThis.Request;
const NativeRequest = getNativeRequest();
class Request {

@@ -287,3 +288,3 @@ runtime;

function patchGlobalRequest() {
const NativeRequest = globalThis[Symbol.for("srvx.nativeRequest")] ??= globalThis.Request;
const NativeRequest = getNativeRequest();
const PatchedRequest = class Request extends NativeRequest {

@@ -321,2 +322,7 @@ static _srvx = true;

}
function getNativeRequest() {
let R = globalThis[kNativeRequest] || globalThis.Request;
while (R?._srvx) R = Object.getPrototypeOf(R);
return globalThis[kNativeRequest] ??= R;
}
const NodeResponse = /* @__PURE__ */ (() => {

@@ -430,2 +436,5 @@ const NativeResponse = globalThis.Response;

})();
function prematureCloseError() {
return Object.assign(/* @__PURE__ */ new Error("Connection closed before response was finished"), { code: "ERR_STREAM_PREMATURE_CLOSE" });
}
var WebRequestSocket = class extends Duplex {

@@ -448,17 +457,19 @@ _httpMessage;

#_writeBody;
#resBodyController;
#resBodyClosed;
_webResBody;
#tos = 0;
constructor(request) {
super({
signal: request.signal,
allowHalfOpen: true
});
super({ allowHalfOpen: true });
this.#request = request;
this._webResBody = new ReadableStream({ start: (controller) => {
this.#resBodyController = controller;
this.#_writeBody = controller.enqueue.bind(controller);
this.once("finish", () => {
this.readyState = "closed";
this.#resBodyClosed = true;
controller.close();
});
} });
addAbortSignal(request.signal, this);
}

@@ -558,2 +569,8 @@ setTimeout(ms, cb) {

});
if (!this.#resBodyClosed) {
this.#resBodyClosed = true;
try {
this.#resBodyController?.error(err ?? prematureCloseError());
} catch {}
}
this.readyState = "closed";

@@ -624,4 +641,10 @@ cb(err ?? void 0);

}
let needDrainSymbol;
function getNeedDrainSymbol(res) {
if (needDrainSymbol === void 0) needDrainSymbol = Object.getOwnPropertySymbols(res).find((s) => s.description === "kNeedDrain") ?? null;
return needDrainSymbol;
}
var WebServerResponse = class extends ServerResponse {
#socket;
#socketError;
constructor(req, socket) {

@@ -634,2 +657,12 @@ super(req);

this.#socket = socket;
socket.once("error", (err) => {
this.#socketError ??= err;
});
socket.on("drain", () => {
const kNeedDrain = getNeedDrainSymbol(this);
if (kNeedDrain && !this[kNeedDrain]) return;
if (this.destroyed || this.writableFinished) return;
if (kNeedDrain) this[kNeedDrain] = false;
this.emit("drain");
});
this.waitToFinish = this.waitToFinish.bind(this);

@@ -639,6 +672,24 @@ this.toWebResponse = this.toWebResponse.bind(this);

waitToFinish() {
if (this.writableFinished) return Promise.resolve();
if (this.#socketError || this.#socket.destroyed) return Promise.reject(this.#socketError ?? prematureCloseError());
if (this.writableEnded) return Promise.resolve();
return new Promise((resolve, reject) => {
this.on("finish", () => resolve());
this.on("error", (err) => reject(err));
const socket = this.#socket;
const settle = (err) => {
this.removeListener("finish", onFinish);
this.removeListener("error", onError);
socket.removeListener("error", onError);
socket.removeListener("close", onClose);
if (err) reject(err);
else resolve();
};
const onFinish = () => settle();
const onError = (err) => settle(err);
const onClose = () => {
if (!this.writableFinished) settle(this.#socketError ?? prematureCloseError());
};
this.on("finish", onFinish);
this.on("error", onError);
socket.on("error", onError);
socket.on("close", onClose);
});

@@ -675,3 +726,3 @@ }

} catch (error) {
console.error(error, { cause: {
if (!(req.signal?.aborted || error?.name === "AbortError" || error?.code === "ERR_STREAM_PREMATURE_CLOSE")) console.error(error, { cause: {
req,

@@ -828,2 +879,2 @@ handler

};
export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
export { NodeResponse as FastResponse, FastURL, NodeRequest, NodeResponse, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };

@@ -1,2 +0,2 @@

import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
import { errorPlugin, wrapFetch } from "../_chunks/_plugins.mjs";
const FastURL = URL;

@@ -3,0 +3,0 @@ const FastResponse = Response;

@@ -1,2 +0,2 @@

import { t as LoadOptions } from "./_chunks/loader.mjs";
import { LoadOptions } from "./_chunks/loader.mjs";
type MainOptions = CLIOptions & {

@@ -3,0 +3,0 @@ args?: string[];

@@ -1,2 +0,2 @@

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/_utils.mjs";
import { bold, cyan, gray, green, magenta, red, url, yellow } from "./_chunks/_utils.mjs";
import { loadServerEntry } from "./loader.mjs";

@@ -182,3 +182,3 @@ import { parseArgs } from "node:util";

name: "srvx",
version: "0.11.15",
version: "0.11.16",
description: "Universal Server."

@@ -201,2 +201,3 @@ };

${gray("$")} ${cyan(command)} serve --host=localhost ${gray("# Bind to localhost only")}
${gray("$")} ${cyan(command)} serve --static=./dist ${gray("# Serve static files (no entry needed)")}
${gray("$")} ${cyan(command)} serve --import=jiti/register ${gray(`# Enable ${url("jiti", "https://github.com/unjs/jiti")} loader`)}

@@ -203,0 +204,0 @@ ${gray("$")} ${cyan(command)} serve --tls --cert=cert.pem --key=key.pem ${gray("# Enable TLS (HTTPS/HTTP2)")}

@@ -1,2 +0,2 @@

import { a as loadServerEntry, i as defaultExts, n as LoadedServerEntry, r as defaultEntries, t as LoadOptions } from "./_chunks/loader.mjs";
import { LoadOptions, LoadedServerEntry, defaultEntries, defaultExts, loadServerEntry } from "./_chunks/loader.mjs";
export { LoadOptions, LoadedServerEntry, defaultEntries, defaultExts, loadServerEntry };

@@ -1,2 +0,2 @@

import { a as green, i as gray, l as yellow, n as bold, s as red, t as blue } from "./_chunks/_utils.mjs";
import { blue, bold, gray, green, red, yellow } from "./_chunks/_utils.mjs";
const statusColors = {

@@ -3,0 +3,0 @@ 1: blue,

@@ -1,2 +0,2 @@

import { t as FastURL } from "./_chunks/_url.mjs";
import { FastURL } from "./_chunks/_url.mjs";
import { createReadStream } from "node:fs";

@@ -3,0 +3,0 @@ import { extname, join, resolve, sep } from "node:path";

{
"name": "srvx",
"version": "0.11.16",
"version": "0.11.17",
"description": "Universal Server.",

@@ -62,16 +62,16 @@ "homepage": "https://srvx.h3.dev",

"devDependencies": {
"@cloudflare/workers-types": "^4.20260521.1",
"@hono/node-server": "^2.0.3",
"@cloudflare/workers-types": "^4.20260617.1",
"@hono/node-server": "^2.0.5",
"@mitata/counters": "^0.0.8",
"@mjackson/node-fetch-server": "^0.7.0",
"@types/aws-lambda": "^8.10.161",
"@types/aws-lambda": "^8.10.162",
"@types/bun": "^1.3.14",
"@types/deno": "^2.7.0",
"@types/express": "^5.0.6",
"@types/node": "^25.9.1",
"@types/node": "^25.9.3",
"@types/node-forge": "^1.3.14",
"@types/serviceworker": "^0.0.197",
"@typescript/native-preview": "7.0.0-dev.20260521.1",
"@vitest/coverage-v8": "^4.1.7",
"@whatwg-node/server": "^0.10.18",
"@typescript/native-preview": "latest",
"@vitest/coverage-v8": "^4.1.9",
"@whatwg-node/server": "^0.11.0",
"automd": "^0.4.3",

@@ -87,10 +87,10 @@ "changelogen": "^0.6.2",

"node-forge": "^1.4.0",
"obuild": "^0.4.35",
"oxfmt": "^0.51.0",
"oxlint": "^1.66.0",
"srvx-release": "npm:srvx@^0.11.15",
"obuild": "^0.4.36",
"oxfmt": "^0.55.0",
"oxlint": "^1.70.0",
"srvx-release": "npm:srvx@^0.11.16",
"tslib": "^2.8.1",
"typescript": "^6.0.3",
"undici": "^8.3.0",
"vitest": "^4.1.7"
"undici": "~8.3",
"vitest": "^4.1.9"
},

@@ -103,3 +103,3 @@ "resolutions": {

},
"packageManager": "pnpm@11.2.2"
"packageManager": "pnpm@11.8.0"
}