@universal-middleware/express 0.4.17 → 0.4.19
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/dist/index.d.ts +1 -2
- package/dist/index.js +18 -12
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http';
|
|
2
2
|
import { Socket } from 'node:net';
|
|
3
|
-
import { Get, UniversalHandler, UniversalFn, Awaitable, UniversalMiddleware, RuntimeAdapterTarget, UniversalRouter, UniversalRouterInterface, EnhancedMiddleware } from '@universal-middleware/core';
|
|
3
|
+
import { Get, UniversalHandler, UniversalFn, contextSymbol, Awaitable, UniversalMiddleware, RuntimeAdapterTarget, UniversalRouter, UniversalRouterInterface, EnhancedMiddleware } from '@universal-middleware/core';
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import { Express as Express$2 } from 'express';
|
|
6
6
|
import { Express as Express$1 } from 'express4';
|
|
@@ -31,7 +31,6 @@ interface NodeRequestAdapterOptions {
|
|
|
31
31
|
/** Create a function that converts a Node HTTP request into a fetch API `Request` object */
|
|
32
32
|
declare function createRequestAdapter(options?: NodeRequestAdapterOptions): (req: DecoratedRequest) => Request;
|
|
33
33
|
|
|
34
|
-
declare const contextSymbol: unique symbol;
|
|
35
34
|
declare const requestSymbol: unique symbol;
|
|
36
35
|
declare const pendingMiddlewaresSymbol: unique symbol;
|
|
37
36
|
declare const wrappedResponseSymbol: unique symbol;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/common.ts
|
|
2
|
-
import { bindUniversal, getAdapterRuntime, universalSymbol } from "@universal-middleware/core";
|
|
2
|
+
import { bindUniversal, contextSymbol, getAdapterRuntime, universalSymbol } from "@universal-middleware/core";
|
|
3
3
|
|
|
4
4
|
// src/request.ts
|
|
5
5
|
var deno = typeof Deno !== "undefined";
|
|
@@ -62,7 +62,6 @@ function convertBody(req) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// src/response.ts
|
|
65
|
-
import { Readable } from "node:stream";
|
|
66
65
|
import { nodeHeadersToWeb } from "@universal-middleware/core";
|
|
67
66
|
var deno2 = typeof Deno !== "undefined";
|
|
68
67
|
async function sendResponse(fetchResponse, nodeResponse) {
|
|
@@ -73,11 +72,12 @@ async function sendResponse(fetchResponse, nodeResponse) {
|
|
|
73
72
|
} else if (typeof fetchBody.pipe === "function") {
|
|
74
73
|
body = fetchBody;
|
|
75
74
|
} else if (typeof fetchBody.pipeTo === "function") {
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
const { Readable: Readable2 } = await import("node:stream");
|
|
76
|
+
if (!deno2 && Readable2.fromWeb) {
|
|
77
|
+
body = Readable2.fromWeb(fetchBody);
|
|
78
78
|
} else {
|
|
79
79
|
const reader = fetchBody.getReader();
|
|
80
|
-
body = new
|
|
80
|
+
body = new Readable2({
|
|
81
81
|
async read() {
|
|
82
82
|
try {
|
|
83
83
|
const { done, value } = await reader.read();
|
|
@@ -96,7 +96,8 @@ async function sendResponse(fetchResponse, nodeResponse) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
} else if (fetchBody) {
|
|
99
|
-
|
|
99
|
+
const { Readable: Readable2 } = await import("node:stream");
|
|
100
|
+
body = Readable2.from(fetchBody);
|
|
100
101
|
}
|
|
101
102
|
setHeaders(fetchResponse, nodeResponse);
|
|
102
103
|
if (body) {
|
|
@@ -218,7 +219,7 @@ function wrapResponse(nodeResponse, next) {
|
|
|
218
219
|
}
|
|
219
220
|
const middlewares = nodeResponse[pendingMiddlewaresSymbol];
|
|
220
221
|
delete nodeResponse[pendingMiddlewaresSymbol];
|
|
221
|
-
let response
|
|
222
|
+
let response;
|
|
222
223
|
try {
|
|
223
224
|
response = responseAdapter(nodeResponse, reader1);
|
|
224
225
|
for (const middleware of middlewares) {
|
|
@@ -281,7 +282,6 @@ function setHeaders(fetchResponse, nodeResponse, mirror = false) {
|
|
|
281
282
|
}
|
|
282
283
|
|
|
283
284
|
// src/common.ts
|
|
284
|
-
var contextSymbol = Symbol.for("unContext");
|
|
285
285
|
var requestSymbol = Symbol.for("unRequest");
|
|
286
286
|
var pendingMiddlewaresSymbol = Symbol.for("unPendingMiddlewares");
|
|
287
287
|
var wrappedResponseSymbol = Symbol.for("unWrappedResponse");
|
|
@@ -391,7 +391,7 @@ function getRuntime(request, response) {
|
|
|
391
391
|
|
|
392
392
|
// src/utils.ts
|
|
393
393
|
import { ServerResponse } from "node:http";
|
|
394
|
-
import { PassThrough, Readable
|
|
394
|
+
import { PassThrough, Readable } from "node:stream";
|
|
395
395
|
var statusCodesWithoutBody = [
|
|
396
396
|
100,
|
|
397
397
|
// Continue
|
|
@@ -414,7 +414,13 @@ function connectToWeb(handler) {
|
|
|
414
414
|
const { res, onReadable } = createServerResponse(req);
|
|
415
415
|
return new Promise(async (resolve, reject) => {
|
|
416
416
|
onReadable(({ readable, headers, statusCode }) => {
|
|
417
|
-
const responseBody = statusCodesWithoutBody.includes(statusCode) ? null :
|
|
417
|
+
const responseBody = statusCodesWithoutBody.includes(statusCode) ? null : "from" in ReadableStream ? (
|
|
418
|
+
// biome-ignore lint/suspicious/noExplicitAny: definition clash between Web and Node
|
|
419
|
+
ReadableStream.from(readable)
|
|
420
|
+
) : (
|
|
421
|
+
// biome-ignore lint/suspicious/noExplicitAny: definition clash between Web and Node
|
|
422
|
+
Readable.toWeb(readable)
|
|
423
|
+
);
|
|
418
424
|
resolve(
|
|
419
425
|
new Response(responseBody, {
|
|
420
426
|
status: statusCode,
|
|
@@ -444,7 +450,7 @@ function connectToWeb(handler) {
|
|
|
444
450
|
function createIncomingMessage(request) {
|
|
445
451
|
const parsedUrl = new URL(request.url, "http://localhost");
|
|
446
452
|
const pathnameAndQuery = (parsedUrl.pathname || "") + (parsedUrl.search || "");
|
|
447
|
-
const body = request.body ?
|
|
453
|
+
const body = request.body ? Readable.fromWeb(request.body) : Readable.from([]);
|
|
448
454
|
return Object.assign(body, {
|
|
449
455
|
url: pathnameAndQuery,
|
|
450
456
|
method: request.method,
|
|
@@ -459,7 +465,7 @@ function createServerResponse(incomingMessage) {
|
|
|
459
465
|
const handleReadable = () => {
|
|
460
466
|
if (handled) return;
|
|
461
467
|
handled = true;
|
|
462
|
-
cb({ readable:
|
|
468
|
+
cb({ readable: Readable.from(passThrough), headers: res.getHeaders(), statusCode: res.statusCode });
|
|
463
469
|
};
|
|
464
470
|
passThrough.once("readable", handleReadable);
|
|
465
471
|
passThrough.once("end", handleReadable);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universal-middleware/express",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express adapter for universal middlewares",
|
|
6
6
|
"files": [
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"repository": "https://github.com/magne4000/universal-middleware",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@universal-middleware/core": "^0.4.
|
|
16
|
+
"@universal-middleware/core": "^0.4.9"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@swc/core": "^1.
|
|
19
|
+
"@swc/core": "^1.13.2",
|
|
20
20
|
"@types/express": "^5.0.3",
|
|
21
21
|
"@types/express4": "npm:@types/express@^4.17.23",
|
|
22
22
|
"@types/node": "^20.19.0",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"helmet": "^8.1.0",
|
|
26
26
|
"rimraf": "^6.0.1",
|
|
27
27
|
"tsup": "^8.5.0",
|
|
28
|
-
"tsx": "^4.
|
|
28
|
+
"tsx": "^4.20.3",
|
|
29
29
|
"typescript": "^5.8.3",
|
|
30
|
-
"vite": "^
|
|
31
|
-
"vitest": "^3.2.
|
|
30
|
+
"vite": "^7.0.6",
|
|
31
|
+
"vitest": "^3.2.4",
|
|
32
32
|
"@universal-middleware/tests": "0.0.0"
|
|
33
33
|
},
|
|
34
34
|
"sideEffects": false,
|