@bool-ts/core 1.5.6 → 1.5.8
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/.prettierrc +11 -11
- package/LICENSE +21 -21
- package/__test/afterDispatcher.ts +9 -9
- package/__test/beforeDispatcher.ts +9 -9
- package/__test/controller.ts +68 -68
- package/__test/firstGuard.ts +10 -10
- package/__test/firstMiddleware.ts +9 -9
- package/__test/index.ts +8 -8
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +22 -22
- package/__test/repository.ts +16 -16
- package/__test/secondGuard.ts +10 -10
- package/__test/secondMiddleware.ts +9 -9
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/entities/route.js +0 -1
- package/dist/hooks/factory.js +1 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -3
- package/jsconfig.json +27 -0
- package/package.json +31 -31
- package/src/decorators/arguments.ts +214 -214
- package/src/decorators/controller.ts +22 -22
- package/src/decorators/dispatcher.ts +19 -19
- package/src/decorators/guard.ts +19 -19
- package/src/decorators/http.ts +81 -81
- package/src/decorators/index.ts +28 -28
- package/src/decorators/inject.ts +13 -13
- package/src/decorators/injectable.ts +8 -8
- package/src/decorators/middleware.ts +19 -19
- package/src/decorators/module.ts +92 -92
- package/src/decorators/zodSchema.ts +20 -20
- package/src/entities/index.ts +3 -3
- package/src/entities/route.ts +327 -328
- package/src/entities/router.ts +35 -35
- package/src/entities/routerGroup.ts +34 -34
- package/src/hooks/factory.ts +616 -616
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +43 -43
- package/src/http/clientError.ts +45 -45
- package/src/http/index.ts +61 -63
- package/src/http/serverError.ts +38 -38
- package/src/index.ts +6 -6
- package/src/interfaces/controller.ts +1 -1
- package/src/interfaces/dispatcher.ts +3 -3
- package/src/interfaces/guard.ts +3 -3
- package/src/interfaces/index.ts +5 -5
- package/src/interfaces/middleware.ts +3 -3
- package/src/interfaces/module.ts +1 -1
- package/test.http +31 -31
- package/tsconfig.json +108 -107
package/src/entities/route.ts
CHANGED
|
@@ -1,328 +1,327 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import type { THttpMethods } from "../http";
|
|
4
|
-
|
|
5
|
-
type THandler<T = unknown> = Required<{
|
|
6
|
-
class: new (...args: Array<any>) => T;
|
|
7
|
-
funcName: string | symbol;
|
|
8
|
-
func: (...args: Array<any>) => unknown;
|
|
9
|
-
}>;
|
|
10
|
-
|
|
11
|
-
export class Route {
|
|
12
|
-
public static rootPattern = ":([a-z0-9A-Z_.-]{1,})";
|
|
13
|
-
|
|
14
|
-
public readonly alias: string;
|
|
15
|
-
|
|
16
|
-
private _map = new Map<keyof THttpMethods, Array<THandler>>();
|
|
17
|
-
|
|
18
|
-
constructor(alias: string) {
|
|
19
|
-
this.alias = this._thinAlias(alias);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public test(
|
|
23
|
-
pathname: string,
|
|
24
|
-
method: keyof THttpMethods
|
|
25
|
-
): Readonly<{ params: Record<string, string>; handlers: Array<THandler> }> | false | undefined {
|
|
26
|
-
try {
|
|
27
|
-
const handlers = this._map.get(method);
|
|
28
|
-
const aliasSplitted = this.alias.split("/");
|
|
29
|
-
const currentPathNameSplitted = this._thinAlias(pathname).split("/");
|
|
30
|
-
|
|
31
|
-
if (!handlers) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Compare splitted length
|
|
36
|
-
if (aliasSplitted.length !== currentPathNameSplitted.length) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const parameters: Record<string, string> = Object();
|
|
41
|
-
|
|
42
|
-
for (let index = 0; index < aliasSplitted.length; index++) {
|
|
43
|
-
const aliasPart = aliasSplitted[index];
|
|
44
|
-
const pathnamePart = currentPathNameSplitted[index];
|
|
45
|
-
|
|
46
|
-
// Check pathmane path match a dynamic syntax, if no match => start compare equal or not
|
|
47
|
-
if (!new RegExp(Route.rootPattern, "g").test(aliasPart)) {
|
|
48
|
-
if (aliasPart !== pathnamePart) return undefined;
|
|
49
|
-
} else {
|
|
50
|
-
let isFailed = false;
|
|
51
|
-
|
|
52
|
-
aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
|
|
53
|
-
if (offset === 0) {
|
|
54
|
-
Object.assign(parameters, {
|
|
55
|
-
[key]: pathnamePart
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return match;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (isFailed) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
* @
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
* @
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*
|
|
187
|
-
* @
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*
|
|
202
|
-
* @
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
*
|
|
217
|
-
* @
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
*
|
|
232
|
-
* @
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
*
|
|
247
|
-
* @
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*
|
|
262
|
-
* @
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
*
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
export default Route;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import type { THttpMethods } from "../http";
|
|
4
|
+
|
|
5
|
+
type THandler<T = unknown> = Required<{
|
|
6
|
+
class: new (...args: Array<any>) => T;
|
|
7
|
+
funcName: string | symbol;
|
|
8
|
+
func: (...args: Array<any>) => unknown;
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
export class Route {
|
|
12
|
+
public static rootPattern = ":([a-z0-9A-Z_.-]{1,})";
|
|
13
|
+
|
|
14
|
+
public readonly alias: string;
|
|
15
|
+
|
|
16
|
+
private _map = new Map<keyof THttpMethods, Array<THandler>>();
|
|
17
|
+
|
|
18
|
+
constructor(alias: string) {
|
|
19
|
+
this.alias = this._thinAlias(alias);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public test(
|
|
23
|
+
pathname: string,
|
|
24
|
+
method: keyof THttpMethods
|
|
25
|
+
): Readonly<{ params: Record<string, string>; handlers: Array<THandler> }> | false | undefined {
|
|
26
|
+
try {
|
|
27
|
+
const handlers = this._map.get(method);
|
|
28
|
+
const aliasSplitted = this.alias.split("/");
|
|
29
|
+
const currentPathNameSplitted = this._thinAlias(pathname).split("/");
|
|
30
|
+
|
|
31
|
+
if (!handlers) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Compare splitted length
|
|
36
|
+
if (aliasSplitted.length !== currentPathNameSplitted.length) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const parameters: Record<string, string> = Object();
|
|
41
|
+
|
|
42
|
+
for (let index = 0; index < aliasSplitted.length; index++) {
|
|
43
|
+
const aliasPart = aliasSplitted[index];
|
|
44
|
+
const pathnamePart = currentPathNameSplitted[index];
|
|
45
|
+
|
|
46
|
+
// Check pathmane path match a dynamic syntax, if no match => start compare equal or not
|
|
47
|
+
if (!new RegExp(Route.rootPattern, "g").test(aliasPart)) {
|
|
48
|
+
if (aliasPart !== pathnamePart) return undefined;
|
|
49
|
+
} else {
|
|
50
|
+
let isFailed = false;
|
|
51
|
+
|
|
52
|
+
aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
|
|
53
|
+
if (offset === 0) {
|
|
54
|
+
Object.assign(parameters, {
|
|
55
|
+
[key]: pathnamePart
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return match;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (isFailed) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return Object.freeze({
|
|
71
|
+
params: parameters,
|
|
72
|
+
handlers: handlers
|
|
73
|
+
});
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(err);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
public isMatch(pathname: string, method: keyof THttpMethods) {
|
|
84
|
+
try {
|
|
85
|
+
const handlers = this._map.get(method);
|
|
86
|
+
|
|
87
|
+
if (!handlers) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const aliasSplitted = this.alias.split("/");
|
|
92
|
+
const currentPathNameSplitted = this._thinAlias(pathname).split("/");
|
|
93
|
+
|
|
94
|
+
// Compare splitted length
|
|
95
|
+
if (aliasSplitted.length !== currentPathNameSplitted.length) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const parameters = Object();
|
|
100
|
+
|
|
101
|
+
for (let index = 0; index < aliasSplitted.length; index++) {
|
|
102
|
+
const aliasPart = aliasSplitted[index];
|
|
103
|
+
const pathnamePart = currentPathNameSplitted[index];
|
|
104
|
+
|
|
105
|
+
// Check pathmane path match a dynamic syntax, if no match => start compare equal or not
|
|
106
|
+
if (!new RegExp(Route.rootPattern, "g").test(aliasPart)) {
|
|
107
|
+
if (aliasPart !== pathnamePart) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
let isFailed = false;
|
|
112
|
+
|
|
113
|
+
aliasPart.replace(new RegExp(Route.rootPattern, "g"), (subString, key, value) => {
|
|
114
|
+
if (!new RegExp(value, "g").test(pathnamePart)) {
|
|
115
|
+
isFailed = true;
|
|
116
|
+
} else {
|
|
117
|
+
Object.assign(parameters, {
|
|
118
|
+
[key]: pathnamePart
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return "";
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (isFailed) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return true;
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.error(err);
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param handlers
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
public get(...handlers: Array<THandler>) {
|
|
145
|
+
const currentHandlers = this._map.get("GET");
|
|
146
|
+
|
|
147
|
+
if (!currentHandlers) {
|
|
148
|
+
this._map.set("GET", handlers);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
* @param handlers
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
public post(...handlers: Array<THandler>) {
|
|
160
|
+
const currentHandlers = this._map.get("POST");
|
|
161
|
+
|
|
162
|
+
if (!currentHandlers) {
|
|
163
|
+
this._map.set("POST", handlers);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
*
|
|
171
|
+
* @param handlers
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
public put(...handlers: Array<THandler>) {
|
|
175
|
+
const currentHandlers = this._map.get("PUT");
|
|
176
|
+
|
|
177
|
+
if (!currentHandlers) {
|
|
178
|
+
this._map.set("PUT", handlers);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
*
|
|
186
|
+
* @param handlers
|
|
187
|
+
* @returns
|
|
188
|
+
*/
|
|
189
|
+
public delete(...handlers: Array<THandler>) {
|
|
190
|
+
const currentHandlers = this._map.get("DELETE");
|
|
191
|
+
|
|
192
|
+
if (!currentHandlers) {
|
|
193
|
+
this._map.set("DELETE", handlers);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
*
|
|
201
|
+
* @param handlers
|
|
202
|
+
* @returns
|
|
203
|
+
*/
|
|
204
|
+
public connect(...handlers: Array<THandler>) {
|
|
205
|
+
const currentHandlers = this._map.get("CONNECT");
|
|
206
|
+
|
|
207
|
+
if (!currentHandlers) {
|
|
208
|
+
return this._map.set("CONNECT", handlers);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* @param handlers
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
219
|
+
public options(...handlers: Array<THandler>) {
|
|
220
|
+
const currentHandlers = this._map.get("OPTIONS");
|
|
221
|
+
|
|
222
|
+
if (!currentHandlers) {
|
|
223
|
+
return this._map.set("OPTIONS", handlers);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
*
|
|
231
|
+
* @param handlers
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
public trace(...handlers: Array<THandler>) {
|
|
235
|
+
const currentHandlers = this._map.get("TRACE");
|
|
236
|
+
|
|
237
|
+
if (!currentHandlers) {
|
|
238
|
+
return this._map.set("TRACE", handlers);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @param handlers
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
public patch(...handlers: Array<THandler>) {
|
|
250
|
+
const currentHandlers = this._map.get("PATCH");
|
|
251
|
+
|
|
252
|
+
if (!currentHandlers) {
|
|
253
|
+
return this._map.set("PATCH", handlers);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @param handlers
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
264
|
+
private _thinAlias(alias: string) {
|
|
265
|
+
return alias.replace(new RegExp("[/]{2,}", "g"), "/").replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Internal get fullpath after check regular expression
|
|
270
|
+
* @returns
|
|
271
|
+
*/
|
|
272
|
+
get _fullPath(): string {
|
|
273
|
+
// Split path to start filter
|
|
274
|
+
const pathSplited = this.alias.split("/");
|
|
275
|
+
|
|
276
|
+
const blockFiltered = pathSplited.map((value, index) => {
|
|
277
|
+
// Initialize full parameter regex to validate
|
|
278
|
+
let validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})(\\(.*?\\))", "g");
|
|
279
|
+
|
|
280
|
+
if (!validateReg.test(value)) {
|
|
281
|
+
// Initialize key parameter regex to validate
|
|
282
|
+
validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})", "g");
|
|
283
|
+
|
|
284
|
+
if (!validateReg.test(value)) {
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return value.replace(validateReg, (value, index) => `${value}(.*?)`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return value;
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
return blockFiltered.join("/");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Internal get filterd path after check regular expression
|
|
299
|
+
* @returns
|
|
300
|
+
*/
|
|
301
|
+
get _filteredPath(): string {
|
|
302
|
+
// Split path to start filter
|
|
303
|
+
const pathSplited = this.alias.split("/");
|
|
304
|
+
|
|
305
|
+
//
|
|
306
|
+
const blockFiltered = pathSplited.map((value, index) => {
|
|
307
|
+
let validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})((.*?))", "g");
|
|
308
|
+
|
|
309
|
+
if (!validateReg.test(value)) {
|
|
310
|
+
// Initialize key parameter regex to validate
|
|
311
|
+
validateReg = new RegExp(":([a-z0-9A-Z_.-]{1,})", "g");
|
|
312
|
+
|
|
313
|
+
if (!validateReg.test(value)) {
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return value.replace(validateReg, (value, index) => "(.*?)");
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return value.replace(validateReg, (subString, arg_01, arg_02) => arg_02);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return blockFiltered.join("/");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export default Route;
|