@bool-ts/core 1.5.7 → 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/jsconfig.json +27 -27
- 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 -61
- 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 -108
package/src/entities/router.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import Route from "./route";
|
|
4
|
-
|
|
5
|
-
export class Router {
|
|
6
|
-
public readonly alias: string;
|
|
7
|
-
|
|
8
|
-
private _routes: Map<string, Route> = new Map();
|
|
9
|
-
|
|
10
|
-
constructor(alias: string) {
|
|
11
|
-
this.alias = this._thinAlias(alias);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public route(alias: string) {
|
|
15
|
-
const thinAlias = this._thinAlias(`${this.alias}/${alias}`);
|
|
16
|
-
const route = this._routes.get(thinAlias);
|
|
17
|
-
const newRoute = !route ? new Route(`${this.alias}/${alias}`) : route;
|
|
18
|
-
|
|
19
|
-
if (!route) {
|
|
20
|
-
this._routes.set(thinAlias, newRoute);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return newRoute;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private _thinAlias(alias: string) {
|
|
27
|
-
return alias.replace(new RegExp("[/]{2,}", "g"), "/").replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get routes() {
|
|
31
|
-
return this._routes;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default Router;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Route from "./route";
|
|
4
|
+
|
|
5
|
+
export class Router {
|
|
6
|
+
public readonly alias: string;
|
|
7
|
+
|
|
8
|
+
private _routes: Map<string, Route> = new Map();
|
|
9
|
+
|
|
10
|
+
constructor(alias: string) {
|
|
11
|
+
this.alias = this._thinAlias(alias);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public route(alias: string) {
|
|
15
|
+
const thinAlias = this._thinAlias(`${this.alias}/${alias}`);
|
|
16
|
+
const route = this._routes.get(thinAlias);
|
|
17
|
+
const newRoute = !route ? new Route(`${this.alias}/${alias}`) : route;
|
|
18
|
+
|
|
19
|
+
if (!route) {
|
|
20
|
+
this._routes.set(thinAlias, newRoute);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return newRoute;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private _thinAlias(alias: string) {
|
|
27
|
+
return alias.replace(new RegExp("[/]{2,}", "g"), "/").replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get routes() {
|
|
31
|
+
return this._routes;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default Router;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import type { THttpMethods } from "../http";
|
|
2
|
-
import type { Router } from "./router";
|
|
3
|
-
|
|
4
|
-
export class RouterGroup {
|
|
5
|
-
private _routers: Map<string, Router> = new Map();
|
|
6
|
-
|
|
7
|
-
public add(...routers: Array<Router>) {
|
|
8
|
-
for (let i = 0; i < routers.length; i++) {
|
|
9
|
-
if (this._routers.has(routers[i].alias)) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
this._routers.set(routers[i].alias, routers[i]);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public find(pathame: string, method: keyof THttpMethods) {
|
|
20
|
-
for (const router of [...this._routers.values()]) {
|
|
21
|
-
for (const route of router.routes.values()) {
|
|
22
|
-
const result = route.test(pathame, method);
|
|
23
|
-
|
|
24
|
-
if (!result) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
import type { THttpMethods } from "../http";
|
|
2
|
+
import type { Router } from "./router";
|
|
3
|
+
|
|
4
|
+
export class RouterGroup {
|
|
5
|
+
private _routers: Map<string, Router> = new Map();
|
|
6
|
+
|
|
7
|
+
public add(...routers: Array<Router>) {
|
|
8
|
+
for (let i = 0; i < routers.length; i++) {
|
|
9
|
+
if (this._routers.has(routers[i].alias)) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this._routers.set(routers[i].alias, routers[i]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public find(pathame: string, method: keyof THttpMethods) {
|
|
20
|
+
for (const router of [...this._routers.values()]) {
|
|
21
|
+
for (const route of router.routes.values()) {
|
|
22
|
+
const result = route.test(pathame, method);
|
|
23
|
+
|
|
24
|
+
if (!result) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|