@tsed/platform-express 8.12.5 → 8.13.1
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.
|
@@ -5,9 +5,11 @@ import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
|
5
5
|
import { adapter, application, createContext, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformResponse } from "@tsed/platform-http";
|
|
6
6
|
import { PlatformHandlerType } from "@tsed/platform-router";
|
|
7
7
|
import Express from "express";
|
|
8
|
+
import { version } from "express/package.json" with { type: "json" };
|
|
8
9
|
import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
9
10
|
import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
|
|
10
11
|
import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
|
|
12
|
+
import { convertPath } from "../utils/convertPath.js";
|
|
11
13
|
function callNext(next, metadata, $ctx) {
|
|
12
14
|
if (metadata.type !== PlatformHandlerType.RESPONSE_FN) {
|
|
13
15
|
return next && $ctx.error && !$ctx.isDone() ? next($ctx.error) : next();
|
|
@@ -67,13 +69,24 @@ export class PlatformExpress extends PlatformAdapter {
|
|
|
67
69
|
}
|
|
68
70
|
mapLayers(layers) {
|
|
69
71
|
const rawApp = this.app.getApp();
|
|
72
|
+
const v = `v${version.split(".")[0]}`;
|
|
70
73
|
layers.forEach((layer) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
const handlers = layer.getArgs(false);
|
|
75
|
+
const { path, wildcard } = convertPath(layer.path, v);
|
|
76
|
+
layer.path = path;
|
|
77
|
+
if (layer.method === "statics") {
|
|
78
|
+
rawApp.use(path, this.statics(path, layer.opts));
|
|
79
|
+
return;
|
|
75
80
|
}
|
|
76
|
-
|
|
81
|
+
if (wildcard) {
|
|
82
|
+
handlers.unshift(((req, _, next) => {
|
|
83
|
+
if (req.params["0"] && !req.params[wildcard]) {
|
|
84
|
+
req.params[wildcard] = req.params["0"];
|
|
85
|
+
}
|
|
86
|
+
next();
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
rawApp[layer.method](path, ...handlers);
|
|
77
90
|
});
|
|
78
91
|
}
|
|
79
92
|
mapHandler(handler, metadata) {
|
package/lib/esm/index.js
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isString } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a path to v4 format
|
|
4
|
+
*/
|
|
5
|
+
function convertPathToV4(path) {
|
|
6
|
+
const segments = path.split("/");
|
|
7
|
+
const parsed = segments.reduce((options, segment, index) => {
|
|
8
|
+
const isLastSegment = index === segments.length - 1;
|
|
9
|
+
if (isLastSegment && (segment === "*" || segment === "(.*)")) {
|
|
10
|
+
options.wildcard = "*";
|
|
11
|
+
options.path.push("*");
|
|
12
|
+
return options;
|
|
13
|
+
}
|
|
14
|
+
if (isLastSegment && segment.startsWith("*")) {
|
|
15
|
+
options.wildcard = segment.substring(1);
|
|
16
|
+
options.path.push("*");
|
|
17
|
+
return options;
|
|
18
|
+
}
|
|
19
|
+
if (segment.startsWith(":") && segment.endsWith("*")) {
|
|
20
|
+
options.wildcard = segment.substring(1, segment.length - 1);
|
|
21
|
+
options.path.push("*");
|
|
22
|
+
return options;
|
|
23
|
+
}
|
|
24
|
+
if (segment.startsWith("{")) {
|
|
25
|
+
// Handle v5 style parameters like /{param}
|
|
26
|
+
const paramName = segment.substring(1, segment.length - 1);
|
|
27
|
+
options.path.push(`${paramName}?`);
|
|
28
|
+
return options;
|
|
29
|
+
}
|
|
30
|
+
options.path.push(segment);
|
|
31
|
+
return options;
|
|
32
|
+
}, { path: [], wildcard: undefined });
|
|
33
|
+
return {
|
|
34
|
+
path: parsed.path.join("/"),
|
|
35
|
+
wildcard: parsed.wildcard
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a path to v5 format
|
|
40
|
+
*/
|
|
41
|
+
function convertPathToV5(path) {
|
|
42
|
+
const segments = path.split("/");
|
|
43
|
+
const parsed = segments.reduce((options, segment, index) => {
|
|
44
|
+
const isLastSegment = index === segments.length - 1;
|
|
45
|
+
if (isLastSegment && (segment === "*" || segment === "(.*)")) {
|
|
46
|
+
options.wildcard = "*";
|
|
47
|
+
options.path.push("{*wildcard}");
|
|
48
|
+
return options;
|
|
49
|
+
}
|
|
50
|
+
if (isLastSegment && segment.startsWith("*")) {
|
|
51
|
+
options.wildcard = segment.substring(1);
|
|
52
|
+
options.path.push(segment);
|
|
53
|
+
return options;
|
|
54
|
+
}
|
|
55
|
+
if (segment.startsWith(":")) {
|
|
56
|
+
if (segment.endsWith("?")) {
|
|
57
|
+
options.path.push(`{:${segment.substring(1, segment.length - 1)}}`);
|
|
58
|
+
return options;
|
|
59
|
+
}
|
|
60
|
+
if (isLastSegment && segment.endsWith("*")) {
|
|
61
|
+
options.wildcard = segment.substring(1, segment.length - 1);
|
|
62
|
+
options.path.push(`{*${options.wildcard}}`);
|
|
63
|
+
return options;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (isLastSegment && segment.startsWith("{*")) {
|
|
67
|
+
// Handle v5 style parameters like /{param}
|
|
68
|
+
options.wildcard = segment.substring(2, segment.length - 1);
|
|
69
|
+
}
|
|
70
|
+
options.path.push(segment);
|
|
71
|
+
return options;
|
|
72
|
+
}, { path: [], wildcard: undefined });
|
|
73
|
+
return {
|
|
74
|
+
path: parsed.path.join("/"),
|
|
75
|
+
wildcard: parsed.wildcard
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Converts a path between v4 and v5 formats
|
|
80
|
+
*/
|
|
81
|
+
export function convertPath(path, framework) {
|
|
82
|
+
if (isString(path)) {
|
|
83
|
+
if (framework === "v4") {
|
|
84
|
+
return convertPathToV4(path);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return convertPathToV5(path);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { path };
|
|
91
|
+
}
|
|
@@ -49,7 +49,7 @@ export declare class PlatformExpress extends PlatformAdapter<Express.Application
|
|
|
49
49
|
app: Express.Express;
|
|
50
50
|
callback: () => Express.Express;
|
|
51
51
|
};
|
|
52
|
-
statics(endpoint: string, options: PlatformStaticsOptions): (request: any, response: any, next: any) => void;
|
|
52
|
+
statics(endpoint: string | RegExp, options: PlatformStaticsOptions): (request: any, response: any, next: any) => void;
|
|
53
53
|
bodyParser(type: "json" | "text" | "urlencoded", additionalOptions?: any): any;
|
|
54
54
|
private configureViewsEngine;
|
|
55
55
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Framework = "v4" | "v5";
|
|
2
|
+
interface ConvertPathResult {
|
|
3
|
+
path: string | RegExp;
|
|
4
|
+
wildcard?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Converts a path between v4 and v5 formats
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertPath(path: string | RegExp, framework: Framework): ConvertPathResult;
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/platform-express",
|
|
3
3
|
"description": "A TypeScript Framework on top of Express",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.13.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -58,20 +58,19 @@
|
|
|
58
58
|
"tslib": "2.7.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@tsed/barrels": "8.
|
|
62
|
-
"@tsed/core": "8.
|
|
63
|
-
"@tsed/di": "8.
|
|
64
|
-
"@tsed/platform-http": "8.
|
|
65
|
-
"@tsed/platform-test-sdk": "8.
|
|
66
|
-
"@tsed/platform-views": "8.
|
|
67
|
-
"@tsed/typescript": "8.
|
|
61
|
+
"@tsed/barrels": "8.13.1",
|
|
62
|
+
"@tsed/core": "8.13.1",
|
|
63
|
+
"@tsed/di": "8.13.1",
|
|
64
|
+
"@tsed/platform-http": "8.13.1",
|
|
65
|
+
"@tsed/platform-test-sdk": "8.13.1",
|
|
66
|
+
"@tsed/platform-views": "8.13.1",
|
|
67
|
+
"@tsed/typescript": "8.13.1",
|
|
68
68
|
"@types/body-parser": "1.19.5",
|
|
69
69
|
"@types/compression": "1.7.5",
|
|
70
70
|
"@types/cookie-parser": "1.4.7",
|
|
71
71
|
"@types/express": "^4.17.21",
|
|
72
72
|
"@types/express-session": "1.18.1",
|
|
73
73
|
"@types/method-override": "0.0.35",
|
|
74
|
-
"@types/multer": "^1.4.12",
|
|
75
74
|
"body-parser": "1.20.3",
|
|
76
75
|
"compression": "1.7.4",
|
|
77
76
|
"cookie-parser": "1.4.6",
|
|
@@ -82,7 +81,7 @@
|
|
|
82
81
|
"express-session": "1.18.1",
|
|
83
82
|
"method-override": "3.0.0",
|
|
84
83
|
"typescript": "5.4.5",
|
|
85
|
-
"vitest": "3.
|
|
84
|
+
"vitest": "3.2.4"
|
|
86
85
|
},
|
|
87
86
|
"peerDependencies": {
|
|
88
87
|
"@tsed/core": ">=8.0.0",
|
|
@@ -93,7 +92,6 @@
|
|
|
93
92
|
"@tsed/platform-http": ">=8.0.0",
|
|
94
93
|
"@tsed/platform-views": ">=8.0.0",
|
|
95
94
|
"@tsed/schema": ">=8.0.0",
|
|
96
|
-
"@types/multer": "^1.4.5",
|
|
97
95
|
"body-parser": "^1.19.0",
|
|
98
96
|
"cross-env": "7.0.3",
|
|
99
97
|
"express": ">=4.17.1",
|