@universal-middleware/express 0.2.4 → 0.2.6
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/LICENSE +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -17
- package/package.json +22 -23
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Joël Charles
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ interface DecoratedRequest<C extends Universal.Context = Universal.Context> exte
|
|
|
45
45
|
socket?: PossiblyEncryptedSocket;
|
|
46
46
|
rawBody?: Buffer | null;
|
|
47
47
|
originalUrl?: string;
|
|
48
|
+
params?: Record<string, string>;
|
|
48
49
|
[contextSymbol]?: C;
|
|
49
50
|
[requestSymbol]?: Request;
|
|
50
51
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/common.ts
|
|
2
|
+
import { getAdapterRuntime } from "@universal-middleware/core";
|
|
3
|
+
|
|
1
4
|
// src/request.ts
|
|
2
5
|
var deno = typeof Deno !== "undefined";
|
|
3
6
|
var bun = typeof Bun !== "undefined";
|
|
@@ -163,7 +166,6 @@ function setHeaders(fetchResponse, nodeResponse, mirror = false) {
|
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
// src/common.ts
|
|
166
|
-
import { getAdapterRuntime } from "@universal-middleware/core";
|
|
167
169
|
var contextSymbol = Symbol("unContext");
|
|
168
170
|
var requestSymbol = Symbol("unRequest");
|
|
169
171
|
var pendingMiddlewaresSymbol = Symbol("unPendingMiddlewares");
|
|
@@ -177,14 +179,7 @@ function createHandler(handlerFactory, options = {}) {
|
|
|
177
179
|
try {
|
|
178
180
|
req[contextSymbol] ??= {};
|
|
179
181
|
const request = requestAdapter(req);
|
|
180
|
-
const response = await handler(
|
|
181
|
-
request,
|
|
182
|
-
req[contextSymbol],
|
|
183
|
-
getAdapterRuntime("node", {
|
|
184
|
-
req,
|
|
185
|
-
res
|
|
186
|
-
})
|
|
187
|
-
);
|
|
182
|
+
const response = await handler(request, req[contextSymbol], getRuntime(req, res));
|
|
188
183
|
await sendResponse(response, res);
|
|
189
184
|
} catch (error) {
|
|
190
185
|
if (next) {
|
|
@@ -210,14 +205,7 @@ function createMiddleware(middlewareFactory, options = {}) {
|
|
|
210
205
|
try {
|
|
211
206
|
req[contextSymbol] ??= {};
|
|
212
207
|
const request = requestAdapter(req);
|
|
213
|
-
const response = await middleware(
|
|
214
|
-
request,
|
|
215
|
-
getContext(req),
|
|
216
|
-
getAdapterRuntime("node", {
|
|
217
|
-
req,
|
|
218
|
-
res
|
|
219
|
-
})
|
|
220
|
-
);
|
|
208
|
+
const response = await middleware(request, getContext(req), getRuntime(req, res));
|
|
221
209
|
if (!response) {
|
|
222
210
|
return next?.();
|
|
223
211
|
}
|
|
@@ -257,6 +245,13 @@ function createMiddleware(middlewareFactory, options = {}) {
|
|
|
257
245
|
function getContext(req) {
|
|
258
246
|
return req[contextSymbol];
|
|
259
247
|
}
|
|
248
|
+
function getRuntime(request, response) {
|
|
249
|
+
return getAdapterRuntime("express", {
|
|
250
|
+
params: request.params,
|
|
251
|
+
req: request,
|
|
252
|
+
res: response
|
|
253
|
+
});
|
|
254
|
+
}
|
|
260
255
|
export {
|
|
261
256
|
createHandler,
|
|
262
257
|
createMiddleware,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universal-middleware/express",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express adapter for universal middlewares",
|
|
6
6
|
"files": [
|
|
@@ -12,36 +12,23 @@
|
|
|
12
12
|
"author": "Joël Charles <joel.charles91@gmail.com>",
|
|
13
13
|
"repository": "https://github.com/magne4000/universal-handler",
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "rimraf dist && tsup",
|
|
17
|
-
"dev": "tsup --watch",
|
|
18
|
-
"prepack": "pnpm build",
|
|
19
|
-
"test": "vitest run",
|
|
20
|
-
"test:run-express:node": "tsx tests/entry-express.ts",
|
|
21
|
-
"test:run-express:bun": "bun tests/entry-express.ts",
|
|
22
|
-
"test:run-express:deno": "deno run --unstable-byonm --unstable-sloppy-imports -A tests/entry-express.ts",
|
|
23
|
-
"test:typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
-
"release": "LANG=en_US release-me patch",
|
|
25
|
-
"release:minor": "LANG=en_US release-me minor",
|
|
26
|
-
"release:commit": "LANG=en_US release-me commit"
|
|
27
|
-
},
|
|
28
15
|
"dependencies": {
|
|
29
|
-
"@universal-middleware/core": "
|
|
16
|
+
"@universal-middleware/core": "^0.2.9"
|
|
30
17
|
},
|
|
31
18
|
"devDependencies": {
|
|
32
|
-
"@brillout/release-me": "^0.4.
|
|
19
|
+
"@brillout/release-me": "^0.4.1",
|
|
33
20
|
"@swc/core": "^1.7.11",
|
|
34
|
-
"@types/express": "
|
|
35
|
-
"@types/node": "
|
|
36
|
-
"
|
|
37
|
-
"express": "catalog:",
|
|
21
|
+
"@types/express": "^4.17.21",
|
|
22
|
+
"@types/node": "^20.16.5",
|
|
23
|
+
"express": "^4.19.2",
|
|
38
24
|
"helmet": "^7.1.0",
|
|
39
25
|
"rimraf": "^6.0.0",
|
|
40
26
|
"tsup": "^8.2.4",
|
|
41
27
|
"tsx": "^4.19.0",
|
|
42
28
|
"typescript": "^5.5.4",
|
|
43
29
|
"vite": "^5.4.3",
|
|
44
|
-
"vitest": "^2.0.5"
|
|
30
|
+
"vitest": "^2.0.5",
|
|
31
|
+
"@universal-middleware/tests": "0.0.0"
|
|
45
32
|
},
|
|
46
33
|
"sideEffects": false,
|
|
47
34
|
"keywords": [
|
|
@@ -54,5 +41,17 @@
|
|
|
54
41
|
"universal-server",
|
|
55
42
|
"context-middleware",
|
|
56
43
|
"request-handling"
|
|
57
|
-
]
|
|
58
|
-
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rimraf dist && tsup",
|
|
47
|
+
"dev": "tsup --watch",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:run-express:node": "tsx tests/entry-express.ts",
|
|
50
|
+
"test:run-express:bun": "bun tests/entry-express.ts",
|
|
51
|
+
"test:run-express:deno": "deno run --unstable-byonm --unstable-sloppy-imports -A tests/entry-express.ts",
|
|
52
|
+
"test:typecheck": "tsc -p tsconfig.json --noEmit",
|
|
53
|
+
"release": "LANG=en_US release-me patch",
|
|
54
|
+
"release:minor": "LANG=en_US release-me minor",
|
|
55
|
+
"release:commit": "LANG=en_US release-me commit"
|
|
56
|
+
}
|
|
57
|
+
}
|