@bool-ts/core 1.7.4 → 1.7.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/__test/controller.ts +3 -3
- package/dist/entities/route.d.ts +1 -0
- package/dist/entities/route.js +13 -3
- package/package.json +1 -1
- package/src/entities/route.ts +19 -4
- package/test.http +2 -2
package/__test/controller.ts
CHANGED
|
@@ -58,13 +58,13 @@ export class TestController {
|
|
|
58
58
|
console.log("testInject", testInject);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
@Get("abc/:id")
|
|
61
|
+
@Get("abc/:id.xml")
|
|
62
62
|
public get(@Param("id") id: string) {
|
|
63
63
|
console.log("HEHE", id, typeof id);
|
|
64
64
|
console.log("this.testService", this.testService.exec());
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
@Post("abc/:id/provider/:providerId")
|
|
67
|
+
@Post("abc/:id/provider/:providerId.xml")
|
|
68
68
|
public async post(
|
|
69
69
|
@RequestHeaders(headersSchema)
|
|
70
70
|
headers: Zod.infer<typeof headersSchema>,
|
|
@@ -75,7 +75,7 @@ export class TestController {
|
|
|
75
75
|
@RequestBody(bodySchema)
|
|
76
76
|
body: Zod.infer<typeof bodySchema>
|
|
77
77
|
) {
|
|
78
|
-
console.log("req.headers",
|
|
78
|
+
console.log("req.headers", params);
|
|
79
79
|
console.log("===========================");
|
|
80
80
|
}
|
|
81
81
|
|
package/dist/entities/route.d.ts
CHANGED
package/dist/entities/route.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export class Route {
|
|
3
|
-
static rootPattern = ":([a-z0-9A-Z_
|
|
3
|
+
static rootPattern = ":([a-z0-9A-Z_-]{1,})";
|
|
4
|
+
static innerRootPattern = "([a-z0-9A-Z_-]{1,})";
|
|
4
5
|
alias;
|
|
5
6
|
_map = new Map();
|
|
6
7
|
constructor(alias) {
|
|
@@ -19,6 +20,10 @@ export class Route {
|
|
|
19
20
|
return undefined;
|
|
20
21
|
}
|
|
21
22
|
const parameters = Object();
|
|
23
|
+
const matchingRegex = this.alias.replace(new RegExp(Route.rootPattern, "g"), Route.innerRootPattern);
|
|
24
|
+
if (!new RegExp(matchingRegex).test(this._thinAlias(pathname))) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
22
27
|
for (let index = 0; index < aliasSplitted.length; index++) {
|
|
23
28
|
const aliasPart = aliasSplitted[index];
|
|
24
29
|
const pathnamePart = currentPathNameSplitted[index];
|
|
@@ -31,8 +36,13 @@ export class Route {
|
|
|
31
36
|
let isFailed = false;
|
|
32
37
|
aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
|
|
33
38
|
if (offset === 0) {
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
pathnamePart.replace(new RegExp(Route.innerRootPattern, "g"), (innerMatch, innerKey, innerOffset) => {
|
|
40
|
+
if (innerOffset === 0) {
|
|
41
|
+
Object.assign(parameters, {
|
|
42
|
+
[key]: innerMatch
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return innerMatch;
|
|
36
46
|
});
|
|
37
47
|
}
|
|
38
48
|
return match;
|
package/package.json
CHANGED
package/src/entities/route.ts
CHANGED
|
@@ -9,7 +9,8 @@ export type TRouteModel<T = unknown> = Readonly<{
|
|
|
9
9
|
}>;
|
|
10
10
|
|
|
11
11
|
export class Route {
|
|
12
|
-
public static rootPattern = ":([a-z0-9A-Z_
|
|
12
|
+
public static rootPattern = ":([a-z0-9A-Z_-]{1,})";
|
|
13
|
+
public static innerRootPattern = "([a-z0-9A-Z_-]{1,})";
|
|
13
14
|
|
|
14
15
|
public readonly alias: string;
|
|
15
16
|
|
|
@@ -38,6 +39,11 @@ export class Route {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const parameters: Record<string, string> = Object();
|
|
42
|
+
const matchingRegex = this.alias.replace(new RegExp(Route.rootPattern, "g"), Route.innerRootPattern);
|
|
43
|
+
|
|
44
|
+
if (!new RegExp(matchingRegex).test(this._thinAlias(pathname))) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
41
47
|
|
|
42
48
|
for (let index = 0; index < aliasSplitted.length; index++) {
|
|
43
49
|
const aliasPart = aliasSplitted[index];
|
|
@@ -51,9 +57,18 @@ export class Route {
|
|
|
51
57
|
|
|
52
58
|
aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
|
|
53
59
|
if (offset === 0) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
pathnamePart.replace(
|
|
61
|
+
new RegExp(Route.innerRootPattern, "g"),
|
|
62
|
+
(innerMatch, innerKey, innerOffset) => {
|
|
63
|
+
if (innerOffset === 0) {
|
|
64
|
+
Object.assign(parameters, {
|
|
65
|
+
[key]: innerMatch
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return innerMatch;
|
|
70
|
+
}
|
|
71
|
+
);
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
return match;
|
package/test.http
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Send test GET method
|
|
5
|
-
GET http://{{baseUrl}}/test/abc/
|
|
5
|
+
GET http://{{baseUrl}}/test/abc/test-case.html
|
|
6
6
|
|
|
7
7
|
### Send test POST method
|
|
8
|
-
POST http://{{baseUrl}}/test/abc/123/provider/
|
|
8
|
+
POST http://{{baseUrl}}/test/abc/123/provider/1111.xml?options[page]=1&options[limit]=6&options[sort][metadata.latestReviewAt]=desc&options[sort][info.searchCount]=desc&options[sort][createdAt]=desc&populate[0]=__headquarters&populate[1]=__logoMedia HTTP/1.1
|
|
9
9
|
content-type: application/json
|
|
10
10
|
|
|
11
11
|
{
|