@tsed/platform-koa 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.
|
@@ -13,6 +13,7 @@ import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
|
13
13
|
import { PlatformKoaHandler } from "../services/PlatformKoaHandler.js";
|
|
14
14
|
import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
|
|
15
15
|
import { PlatformKoaResponse } from "../services/PlatformKoaResponse.js";
|
|
16
|
+
import { convertPath } from "../utils/convertPath.js";
|
|
16
17
|
// @ts-ignore
|
|
17
18
|
KoaRouter.prototype.$$match = KoaRouter.prototype.match;
|
|
18
19
|
KoaRouter.prototype.match = function match(...args) {
|
|
@@ -62,13 +63,20 @@ export class PlatformKoa extends PlatformAdapter {
|
|
|
62
63
|
const options = constant("koa.router", {});
|
|
63
64
|
const rawRouter = new KoaRouter(options);
|
|
64
65
|
layers.forEach((layer) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
rawRouter[layer.method](...layer.getArgs());
|
|
66
|
+
const { path, wildcard } = convertPath(layer.path);
|
|
67
|
+
layer.path = path;
|
|
68
|
+
if (layer.method === "statics") {
|
|
69
|
+
rawRouter.use(path, this.statics(layer.path, layer.opts));
|
|
70
|
+
return;
|
|
71
71
|
}
|
|
72
|
+
const handlers = layer.getArgs(false);
|
|
73
|
+
if (wildcard === "*") {
|
|
74
|
+
handlers.unshift(((koaContext, next) => {
|
|
75
|
+
koaContext.request.params["*"] = koaContext.request.params["0"];
|
|
76
|
+
return next();
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
rawRouter[layer.method](path, ...handlers);
|
|
72
80
|
});
|
|
73
81
|
application().getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
|
|
74
82
|
}
|
package/lib/esm/index.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isString } from "@tsed/core";
|
|
2
|
+
export function convertPath(path) {
|
|
3
|
+
if (isString(path)) {
|
|
4
|
+
const segments = path.split("/");
|
|
5
|
+
const parsed = segments.reduce((options, segment, index) => {
|
|
6
|
+
const isLastSegment = index === segments.length - 1;
|
|
7
|
+
if (isLastSegment && (segment === "*" || segment === "(.*)")) {
|
|
8
|
+
options.wildcard = "*";
|
|
9
|
+
options.path.push("(.*)");
|
|
10
|
+
return options;
|
|
11
|
+
}
|
|
12
|
+
if (segment.startsWith(":") && segment.endsWith("*")) {
|
|
13
|
+
options.wildcard = segment.substring(1, segment.length - 1);
|
|
14
|
+
options.path.push(segment);
|
|
15
|
+
return options;
|
|
16
|
+
}
|
|
17
|
+
if (isLastSegment && segment.startsWith("*")) {
|
|
18
|
+
options.wildcard = segment.substring(1);
|
|
19
|
+
options.path.push(`:${options.wildcard}*`);
|
|
20
|
+
return options;
|
|
21
|
+
}
|
|
22
|
+
if (segment.startsWith("{:") && segment.endsWith("}")) {
|
|
23
|
+
// Handle v5 style parameters like /{param}
|
|
24
|
+
const paramName = segment.substring(2, segment.length - 1);
|
|
25
|
+
options.path.push(`:${paramName}?`);
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
28
|
+
options.path.push(segment);
|
|
29
|
+
return options;
|
|
30
|
+
}, { path: [], wildcard: undefined });
|
|
31
|
+
return {
|
|
32
|
+
path: parsed.path.join("/"),
|
|
33
|
+
wildcard: parsed.wildcard
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { path };
|
|
37
|
+
}
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
3
|
"description": "Koa package for Ts.ED framework",
|
|
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",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"repository": "https://github.com/tsedio/tsed",
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@koa/cors": "5.0.0",
|
|
57
|
-
"@tsed/barrels": "8.
|
|
58
|
-
"@tsed/core": "8.
|
|
59
|
-
"@tsed/di": "8.
|
|
60
|
-
"@tsed/platform-http": "8.
|
|
61
|
-
"@tsed/platform-test-sdk": "8.
|
|
62
|
-
"@tsed/typescript": "8.
|
|
57
|
+
"@tsed/barrels": "8.13.1",
|
|
58
|
+
"@tsed/core": "8.13.1",
|
|
59
|
+
"@tsed/di": "8.13.1",
|
|
60
|
+
"@tsed/platform-http": "8.13.1",
|
|
61
|
+
"@tsed/platform-test-sdk": "8.13.1",
|
|
62
|
+
"@tsed/typescript": "8.13.1",
|
|
63
63
|
"@types/koa": "2.15.0",
|
|
64
64
|
"@types/koa-bodyparser": "4.3.12",
|
|
65
65
|
"@types/koa-compose": "3.2.8",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"koa-qs": "^3.0.0",
|
|
78
78
|
"koa-session": "6.4.0",
|
|
79
79
|
"typescript": "5.4.5",
|
|
80
|
-
"vitest": "3.
|
|
80
|
+
"vitest": "3.2.4"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@koa/router": "^13.1.0",
|