@bool-ts/core 1.7.17 → 1.8.0
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 +1 -1
- package/__test/controller.ts +1 -1
- package/__test/index.ts +4 -1
- package/__test/module.ts +3 -1
- package/__test/tsconfig.json +109 -0
- package/__test/webSocket.ts +37 -0
- package/__test/webSocketClient.ts +23 -0
- package/dist/decorators/controller.d.ts +3 -3
- package/dist/decorators/controller.js +1 -2
- package/dist/decorators/dispatcher.d.ts +1 -1
- package/dist/decorators/http.d.ts +12 -12
- package/dist/decorators/http.js +1 -1
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/module.d.ts +3 -1
- package/dist/decorators/module.js +9 -2
- package/dist/decorators/webSocket.d.ts +25 -0
- package/dist/decorators/webSocket.js +40 -0
- package/dist/decorators/webSocketArguments.d.ts +22 -0
- package/dist/decorators/webSocketArguments.js +49 -0
- package/dist/decorators/webSocketEvent.d.ts +15 -0
- package/dist/decorators/webSocketEvent.js +24 -0
- package/dist/decorators/zodSchema.js +3 -3
- package/dist/entities/{route.d.ts → httpRoute.d.ts} +12 -12
- package/dist/entities/{route.js → httpRoute.js} +27 -25
- package/dist/entities/httpRouter.d.ts +10 -0
- package/dist/entities/{router.js → httpRouter.js} +7 -5
- package/dist/entities/{routerGroup.d.ts → httpRouterGroup.d.ts} +4 -4
- package/dist/entities/{routerGroup.js → httpRouterGroup.js} +1 -1
- package/dist/entities/index.d.ts +7 -4
- package/dist/entities/index.js +6 -3
- package/dist/entities/webSocketRoute.d.ts +10 -0
- package/dist/entities/webSocketRoute.js +15 -0
- package/dist/entities/webSocketRouter.d.ts +31 -0
- package/dist/entities/webSocketRouter.js +54 -0
- package/dist/entities/webSocketRouterGroup.d.ts +25 -0
- package/dist/entities/webSocketRouterGroup.js +51 -0
- package/dist/hooks/factory.d.ts +0 -39
- package/dist/hooks/factory.js +398 -63
- package/dist/hooks/injector.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/webSocket.d.ts +2 -0
- package/dist/interfaces/webSocket.js +1 -0
- package/dist/keys/index.d.ts +10 -1
- package/dist/keys/index.js +21 -12
- package/dist/ultils/colors.d.ts +30 -0
- package/dist/ultils/colors.js +41 -0
- package/dist/ultils/index.d.ts +2 -0
- package/dist/ultils/index.js +2 -0
- package/dist/ultils/socket.d.ts +1 -0
- package/dist/ultils/socket.js +7 -0
- package/package.json +7 -7
- package/src/decorators/controller.ts +5 -4
- package/src/decorators/dispatcher.ts +2 -1
- package/src/decorators/guard.ts +1 -0
- package/src/decorators/http.ts +3 -3
- package/src/decorators/index.ts +10 -0
- package/src/decorators/middleware.ts +1 -0
- package/src/decorators/module.ts +14 -3
- package/src/decorators/webSocket.ts +81 -0
- package/src/decorators/webSocketArguments.ts +144 -0
- package/src/decorators/webSocketEvent.ts +56 -0
- package/src/decorators/zodSchema.ts +5 -3
- package/src/entities/{route.ts → httpRoute.ts} +71 -57
- package/src/entities/{router.ts → httpRouter.ts} +8 -6
- package/src/entities/{routerGroup.ts → httpRouterGroup.ts} +4 -4
- package/src/entities/index.ts +7 -4
- package/src/entities/webSocketRoute.ts +27 -0
- package/src/entities/webSocketRouter.ts +64 -0
- package/src/entities/webSocketRouterGroup.ts +64 -0
- package/src/hooks/factory.ts +622 -95
- package/src/hooks/injector.ts +2 -2
- package/src/index.ts +1 -1
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/webSocket.ts +1 -0
- package/src/keys/index.ts +22 -12
- package/src/ultils/colors.ts +56 -0
- package/src/ultils/index.ts +3 -1
- package/src/ultils/socket.ts +9 -0
- package/test.ts +0 -0
- package/tsconfig.json +3 -2
- package/dist/entities/router.d.ts +0 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { THttpMethods } from "../http";
|
|
2
|
-
export type
|
|
2
|
+
export type THttpRouteModel<T = unknown> = Readonly<{
|
|
3
3
|
class: new (...args: Array<any>) => T;
|
|
4
4
|
funcName: string | symbol;
|
|
5
5
|
func: (...args: Array<any>) => unknown;
|
|
6
6
|
}>;
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class HttpRoute {
|
|
8
8
|
static rootPattern: string;
|
|
9
9
|
static innerRootPattern: string;
|
|
10
10
|
readonly alias: string;
|
|
@@ -12,7 +12,7 @@ export declare class Route {
|
|
|
12
12
|
constructor(alias: string);
|
|
13
13
|
test(pathname: string, method: keyof THttpMethods): Readonly<{
|
|
14
14
|
parameters: Record<string, string>;
|
|
15
|
-
model:
|
|
15
|
+
model: THttpRouteModel;
|
|
16
16
|
}> | false | undefined;
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
@@ -23,31 +23,31 @@ export declare class Route {
|
|
|
23
23
|
* @param handlers
|
|
24
24
|
* @returns
|
|
25
25
|
*/
|
|
26
|
-
get(handler:
|
|
26
|
+
get(handler: THttpRouteModel): this;
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
29
|
* @param handlers
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
post(handler:
|
|
32
|
+
post(handler: THttpRouteModel): this;
|
|
33
33
|
/**
|
|
34
34
|
*
|
|
35
35
|
* @param handlers
|
|
36
36
|
* @returns
|
|
37
37
|
*/
|
|
38
|
-
put(handler:
|
|
38
|
+
put(handler: THttpRouteModel): this;
|
|
39
39
|
/**
|
|
40
40
|
*
|
|
41
41
|
* @param handlers
|
|
42
42
|
* @returns
|
|
43
43
|
*/
|
|
44
|
-
delete(handler:
|
|
44
|
+
delete(handler: THttpRouteModel): this;
|
|
45
45
|
/**
|
|
46
46
|
*
|
|
47
47
|
* @param handlers
|
|
48
48
|
* @returns
|
|
49
49
|
*/
|
|
50
|
-
connect(handler:
|
|
50
|
+
connect(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
|
|
51
51
|
class: new (...args: Array<any>) => unknown;
|
|
52
52
|
funcName: string | symbol;
|
|
53
53
|
func: (...args: Array<any>) => unknown;
|
|
@@ -57,7 +57,7 @@ export declare class Route {
|
|
|
57
57
|
* @param handlers
|
|
58
58
|
* @returns
|
|
59
59
|
*/
|
|
60
|
-
options(handler:
|
|
60
|
+
options(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
|
|
61
61
|
class: new (...args: Array<any>) => unknown;
|
|
62
62
|
funcName: string | symbol;
|
|
63
63
|
func: (...args: Array<any>) => unknown;
|
|
@@ -67,7 +67,7 @@ export declare class Route {
|
|
|
67
67
|
* @param handlers
|
|
68
68
|
* @returns
|
|
69
69
|
*/
|
|
70
|
-
trace(handler:
|
|
70
|
+
trace(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
|
|
71
71
|
class: new (...args: Array<any>) => unknown;
|
|
72
72
|
funcName: string | symbol;
|
|
73
73
|
func: (...args: Array<any>) => unknown;
|
|
@@ -77,7 +77,7 @@ export declare class Route {
|
|
|
77
77
|
* @param handlers
|
|
78
78
|
* @returns
|
|
79
79
|
*/
|
|
80
|
-
patch(handler:
|
|
80
|
+
patch(handler: THttpRouteModel): this | Map<keyof THttpMethods, Readonly<{
|
|
81
81
|
class: new (...args: Array<any>) => unknown;
|
|
82
82
|
funcName: string | symbol;
|
|
83
83
|
func: (...args: Array<any>) => unknown;
|
|
@@ -99,4 +99,4 @@ export declare class Route {
|
|
|
99
99
|
*/
|
|
100
100
|
get _filteredPath(): string;
|
|
101
101
|
}
|
|
102
|
-
export default
|
|
102
|
+
export default HttpRoute;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
export class
|
|
2
|
+
export class HttpRoute {
|
|
3
3
|
static rootPattern = ":([a-z0-9A-Z_-]{1,})";
|
|
4
4
|
static innerRootPattern = "([a-z0-9A-Z_-]{1,})";
|
|
5
5
|
alias;
|
|
@@ -20,7 +20,7 @@ export class Route {
|
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
22
|
const parameters = Object();
|
|
23
|
-
const matchingRegex = this.alias.replace(new RegExp(
|
|
23
|
+
const matchingRegex = this.alias.replace(new RegExp(HttpRoute.rootPattern, "g"), HttpRoute.innerRootPattern);
|
|
24
24
|
if (!new RegExp(matchingRegex).test(this._thinAlias(pathname))) {
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
@@ -28,15 +28,15 @@ export class Route {
|
|
|
28
28
|
const aliasPart = aliasSplitted[index];
|
|
29
29
|
const pathnamePart = currentPathNameSplitted[index];
|
|
30
30
|
// Check pathmane path match a dynamic syntax, if no match => start compare equal or not
|
|
31
|
-
if (!new RegExp(
|
|
31
|
+
if (!new RegExp(HttpRoute.rootPattern, "g").test(aliasPart)) {
|
|
32
32
|
if (aliasPart !== pathnamePart)
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
let isFailed = false;
|
|
37
|
-
aliasPart.replace(new RegExp(
|
|
37
|
+
aliasPart.replace(new RegExp(HttpRoute.rootPattern, "g"), (match, key, offset) => {
|
|
38
38
|
if (offset === 0) {
|
|
39
|
-
pathnamePart.replace(new RegExp(
|
|
39
|
+
pathnamePart.replace(new RegExp(HttpRoute.innerRootPattern, "g"), (innerMatch, innerKey, innerOffset) => {
|
|
40
40
|
if (innerOffset === 0) {
|
|
41
41
|
Object.assign(parameters, {
|
|
42
42
|
[key]: innerMatch
|
|
@@ -83,14 +83,14 @@ export class Route {
|
|
|
83
83
|
const aliasPart = aliasSplitted[index];
|
|
84
84
|
const pathnamePart = currentPathNameSplitted[index];
|
|
85
85
|
// Check pathmane path match a dynamic syntax, if no match => start compare equal or not
|
|
86
|
-
if (!new RegExp(
|
|
86
|
+
if (!new RegExp(HttpRoute.rootPattern, "g").test(aliasPart)) {
|
|
87
87
|
if (aliasPart !== pathnamePart) {
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
let isFailed = false;
|
|
93
|
-
aliasPart.replace(new RegExp(
|
|
93
|
+
aliasPart.replace(new RegExp(HttpRoute.rootPattern, "g"), (subString, key, value) => {
|
|
94
94
|
if (!new RegExp(value, "g").test(pathnamePart)) {
|
|
95
95
|
isFailed = true;
|
|
96
96
|
}
|
|
@@ -120,8 +120,8 @@ export class Route {
|
|
|
120
120
|
* @returns
|
|
121
121
|
*/
|
|
122
122
|
get(handler) {
|
|
123
|
-
const
|
|
124
|
-
if (!
|
|
123
|
+
const currenTHttpRouteModel = this._map.get("GET");
|
|
124
|
+
if (!currenTHttpRouteModel) {
|
|
125
125
|
this._map.set("GET", handler);
|
|
126
126
|
}
|
|
127
127
|
return this;
|
|
@@ -132,8 +132,8 @@ export class Route {
|
|
|
132
132
|
* @returns
|
|
133
133
|
*/
|
|
134
134
|
post(handler) {
|
|
135
|
-
const
|
|
136
|
-
if (!
|
|
135
|
+
const currenTHttpRouteModel = this._map.get("POST");
|
|
136
|
+
if (!currenTHttpRouteModel) {
|
|
137
137
|
this._map.set("POST", handler);
|
|
138
138
|
}
|
|
139
139
|
return this;
|
|
@@ -144,8 +144,8 @@ export class Route {
|
|
|
144
144
|
* @returns
|
|
145
145
|
*/
|
|
146
146
|
put(handler) {
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
147
|
+
const currenTHttpRouteModel = this._map.get("PUT");
|
|
148
|
+
if (!currenTHttpRouteModel) {
|
|
149
149
|
this._map.set("PUT", handler);
|
|
150
150
|
}
|
|
151
151
|
return this;
|
|
@@ -156,8 +156,8 @@ export class Route {
|
|
|
156
156
|
* @returns
|
|
157
157
|
*/
|
|
158
158
|
delete(handler) {
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
159
|
+
const currenTHttpRouteModel = this._map.get("DELETE");
|
|
160
|
+
if (!currenTHttpRouteModel) {
|
|
161
161
|
this._map.set("DELETE", handler);
|
|
162
162
|
}
|
|
163
163
|
return this;
|
|
@@ -168,8 +168,8 @@ export class Route {
|
|
|
168
168
|
* @returns
|
|
169
169
|
*/
|
|
170
170
|
connect(handler) {
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
171
|
+
const currenTHttpRouteModel = this._map.get("CONNECT");
|
|
172
|
+
if (!currenTHttpRouteModel) {
|
|
173
173
|
return this._map.set("CONNECT", handler);
|
|
174
174
|
}
|
|
175
175
|
return this;
|
|
@@ -180,8 +180,8 @@ export class Route {
|
|
|
180
180
|
* @returns
|
|
181
181
|
*/
|
|
182
182
|
options(handler) {
|
|
183
|
-
const
|
|
184
|
-
if (!
|
|
183
|
+
const currenTHttpRouteModel = this._map.get("OPTIONS");
|
|
184
|
+
if (!currenTHttpRouteModel) {
|
|
185
185
|
return this._map.set("OPTIONS", handler);
|
|
186
186
|
}
|
|
187
187
|
return this;
|
|
@@ -192,8 +192,8 @@ export class Route {
|
|
|
192
192
|
* @returns
|
|
193
193
|
*/
|
|
194
194
|
trace(handler) {
|
|
195
|
-
const
|
|
196
|
-
if (!
|
|
195
|
+
const currenTHttpRouteModel = this._map.get("TRACE");
|
|
196
|
+
if (!currenTHttpRouteModel) {
|
|
197
197
|
return this._map.set("TRACE", handler);
|
|
198
198
|
}
|
|
199
199
|
return this;
|
|
@@ -204,8 +204,8 @@ export class Route {
|
|
|
204
204
|
* @returns
|
|
205
205
|
*/
|
|
206
206
|
patch(handler) {
|
|
207
|
-
const
|
|
208
|
-
if (!
|
|
207
|
+
const currenTHttpRouteModel = this._map.get("PATCH");
|
|
208
|
+
if (!currenTHttpRouteModel) {
|
|
209
209
|
return this._map.set("PATCH", handler);
|
|
210
210
|
}
|
|
211
211
|
return this;
|
|
@@ -216,7 +216,9 @@ export class Route {
|
|
|
216
216
|
* @returns
|
|
217
217
|
*/
|
|
218
218
|
_thinAlias(alias) {
|
|
219
|
-
return alias
|
|
219
|
+
return alias
|
|
220
|
+
.replace(new RegExp("[/]{2,}", "g"), "/")
|
|
221
|
+
.replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
220
222
|
}
|
|
221
223
|
/**
|
|
222
224
|
* Internal get fullpath after check regular expression
|
|
@@ -263,4 +265,4 @@ export class Route {
|
|
|
263
265
|
return blockFiltered.join("/");
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
|
-
export default
|
|
268
|
+
export default HttpRoute;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import HttpRoute from "./httpRoute";
|
|
2
|
+
export declare class HttpRouter {
|
|
3
|
+
readonly alias: string;
|
|
4
|
+
private _routes;
|
|
5
|
+
constructor(alias: string);
|
|
6
|
+
route(alias: string): HttpRoute;
|
|
7
|
+
private _thinAlias;
|
|
8
|
+
get routes(): Map<string, HttpRoute>;
|
|
9
|
+
}
|
|
10
|
+
export default HttpRouter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
export class
|
|
2
|
+
import HttpRoute from "./httpRoute";
|
|
3
|
+
export class HttpRouter {
|
|
4
4
|
alias;
|
|
5
5
|
_routes = new Map();
|
|
6
6
|
constructor(alias) {
|
|
@@ -9,17 +9,19 @@ export class Router {
|
|
|
9
9
|
route(alias) {
|
|
10
10
|
const thinAlias = this._thinAlias(`${this.alias}/${alias}`);
|
|
11
11
|
const route = this._routes.get(thinAlias);
|
|
12
|
-
const newRoute = !route ? new
|
|
12
|
+
const newRoute = !route ? new HttpRoute(`${this.alias}/${alias}`) : route;
|
|
13
13
|
if (!route) {
|
|
14
14
|
this._routes.set(thinAlias, newRoute);
|
|
15
15
|
}
|
|
16
16
|
return newRoute;
|
|
17
17
|
}
|
|
18
18
|
_thinAlias(alias) {
|
|
19
|
-
return alias
|
|
19
|
+
return alias
|
|
20
|
+
.replace(new RegExp("[/]{2,}", "g"), "/")
|
|
21
|
+
.replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
20
22
|
}
|
|
21
23
|
get routes() {
|
|
22
24
|
return this._routes;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
|
-
export default
|
|
27
|
+
export default HttpRouter;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { THttpMethods } from "../http";
|
|
2
|
-
import type {
|
|
3
|
-
export declare class
|
|
2
|
+
import type { HttpRouter } from "./httpRouter";
|
|
3
|
+
export declare class HttpRouterGroup {
|
|
4
4
|
private _routers;
|
|
5
|
-
add(...routers: Array<
|
|
5
|
+
add(...routers: Array<HttpRouter>): this;
|
|
6
6
|
find(pathame: string, method: keyof THttpMethods): Readonly<{
|
|
7
7
|
parameters: Record<string, string>;
|
|
8
|
-
model: import("./
|
|
8
|
+
model: import("./httpRoute").THttpRouteModel;
|
|
9
9
|
}> | undefined;
|
|
10
10
|
}
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export type { THttpRouteModel } from "./httpRoute";
|
|
2
|
+
export { HttpRoute } from "./httpRoute";
|
|
3
|
+
export { HttpRouter } from "./httpRouter";
|
|
4
|
+
export { HttpRouterGroup } from "./httpRouterGroup";
|
|
5
|
+
export { WebSocketRoute } from "./webSocketRoute";
|
|
6
|
+
export { WebSocketRouter } from "./webSocketRouter";
|
|
7
|
+
export { WebSocketRouterGroup } from "./webSocketRouterGroup";
|
package/dist/entities/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { HttpRoute } from "./httpRoute";
|
|
2
|
+
export { HttpRouter } from "./httpRouter";
|
|
3
|
+
export { HttpRouterGroup } from "./httpRouterGroup";
|
|
4
|
+
export { WebSocketRoute } from "./webSocketRoute";
|
|
5
|
+
export { WebSocketRouter } from "./webSocketRouter";
|
|
6
|
+
export { WebSocketRouterGroup } from "./webSocketRouterGroup";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TWebSocketEventHandlerMetadata } from "../decorators";
|
|
2
|
+
export declare class WebSocketRoute {
|
|
3
|
+
readonly eventName: string;
|
|
4
|
+
readonly metadata: TWebSocketEventHandlerMetadata;
|
|
5
|
+
constructor({ eventName, metadata }: {
|
|
6
|
+
eventName: string;
|
|
7
|
+
metadata: TWebSocketEventHandlerMetadata;
|
|
8
|
+
});
|
|
9
|
+
bind(instance: Object): ThisType<WebSocketRoute>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class WebSocketRoute {
|
|
2
|
+
eventName;
|
|
3
|
+
metadata;
|
|
4
|
+
constructor({ eventName, metadata }) {
|
|
5
|
+
this.eventName = eventName;
|
|
6
|
+
this.metadata = metadata;
|
|
7
|
+
}
|
|
8
|
+
bind(instance) {
|
|
9
|
+
if (typeof this.metadata.descriptor.value !== "function") {
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
this.metadata.descriptor.value = this.metadata.descriptor.value.bind(instance);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TWebSocketEventHandlerMetadata } from "../decorators";
|
|
2
|
+
import type { WebSocketRoute } from "./webSocketRoute";
|
|
3
|
+
export declare class WebSocketRouter {
|
|
4
|
+
readonly rawAlias: string;
|
|
5
|
+
readonly alias: string;
|
|
6
|
+
readonly routes: Array<WebSocketRoute>;
|
|
7
|
+
constructor(rawAlias?: string);
|
|
8
|
+
/**
|
|
9
|
+
* Add websocket routes into router and start analysis
|
|
10
|
+
* @param routes
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
addRoutes(...routes: Array<WebSocketRoute>): ThisType<WebSocketRouter>;
|
|
14
|
+
/**
|
|
15
|
+
* Bind context for descriptor handler in the router
|
|
16
|
+
* @param instance
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
bind(instance: Object): this;
|
|
20
|
+
/**
|
|
21
|
+
* Generate map for websocket handler metadata
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
execute(): Map<string, TWebSocketEventHandlerMetadata>;
|
|
25
|
+
/**
|
|
26
|
+
* Handle alias for router, standardize
|
|
27
|
+
* @param alias
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
static thinAlias(alias: string): string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class WebSocketRouter {
|
|
2
|
+
rawAlias;
|
|
3
|
+
alias;
|
|
4
|
+
routes = [];
|
|
5
|
+
constructor(rawAlias = "/") {
|
|
6
|
+
this.rawAlias = rawAlias;
|
|
7
|
+
this.alias = WebSocketRouter.thinAlias(rawAlias);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Add websocket routes into router and start analysis
|
|
11
|
+
* @param routes
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
addRoutes(...routes) {
|
|
15
|
+
for (const route of routes) {
|
|
16
|
+
if (!this.routes.includes(route)) {
|
|
17
|
+
this.routes.push(route);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Bind context for descriptor handler in the router
|
|
24
|
+
* @param instance
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
bind(instance) {
|
|
28
|
+
for (const route of this.routes) {
|
|
29
|
+
route.bind(instance);
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Generate map for websocket handler metadata
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
execute() {
|
|
38
|
+
const map = new Map();
|
|
39
|
+
for (const route of this.routes) {
|
|
40
|
+
map.set(`${this.alias}:::${route.eventName}`, route.metadata);
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Handle alias for router, standardize
|
|
46
|
+
* @param alias
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
static thinAlias(alias) {
|
|
50
|
+
return alias
|
|
51
|
+
.replace(new RegExp("[/]{2,}", "g"), "/")
|
|
52
|
+
.replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TWebSocketEventHandlerMetadata } from "../decorators";
|
|
2
|
+
import type { WebSocketRouter } from "./webSocketRouter";
|
|
3
|
+
export declare class WebSocketRouterGroup {
|
|
4
|
+
readonly rawPrefix: string;
|
|
5
|
+
readonly prefix: string;
|
|
6
|
+
readonly routers: Array<WebSocketRouter>;
|
|
7
|
+
constructor(rawPrefix?: string);
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param routers
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
addRouters(...routers: Array<WebSocketRouter>): ThisType<WebSocketRouterGroup>;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
execute(): Map<string, TWebSocketEventHandlerMetadata>;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param prefix
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
static thinPrefix(prefix: string): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class WebSocketRouterGroup {
|
|
2
|
+
rawPrefix;
|
|
3
|
+
prefix;
|
|
4
|
+
routers = [];
|
|
5
|
+
constructor(rawPrefix = "/") {
|
|
6
|
+
this.rawPrefix = rawPrefix;
|
|
7
|
+
this.prefix = WebSocketRouterGroup.thinPrefix(rawPrefix);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param routers
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
addRouters(...routers) {
|
|
15
|
+
for (let i = 0; i < routers.length; i++) {
|
|
16
|
+
if (!this.routers.includes(routers[i])) {
|
|
17
|
+
this.routers.push(routers[i]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const router of routers) {
|
|
21
|
+
if (!this.routers.includes(router)) {
|
|
22
|
+
this.routers.push(router);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
execute() {
|
|
32
|
+
const map = new Map();
|
|
33
|
+
for (const router of this.routers) {
|
|
34
|
+
const routerMap = router.execute();
|
|
35
|
+
for (const [routerKey, metadata] of routerMap.entries()) {
|
|
36
|
+
map.set(`/${WebSocketRouterGroup.thinPrefix(`${this.prefix}/${routerKey}`)}`, metadata);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param prefix
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
static thinPrefix(prefix) {
|
|
47
|
+
return prefix
|
|
48
|
+
.replace(new RegExp("[/]{2,}", "g"), "/")
|
|
49
|
+
.replace(new RegExp("^[/]|[/]$", "g"), "");
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/hooks/factory.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type { IMiddleware } from "../interfaces";
|
|
2
|
-
import type { IDispatcher } from "../interfaces/dispatcher";
|
|
3
|
-
import "colors";
|
|
4
1
|
import "reflect-metadata";
|
|
5
2
|
import Qs from "qs";
|
|
6
|
-
import * as Zod from "zod";
|
|
7
|
-
import { RouterGroup } from "../entities";
|
|
8
|
-
import { Injector } from "./injector";
|
|
9
3
|
export type TGroupElementModel<TFuncName extends keyof TClass, TClass extends Object = Object, TFunc = TClass[TFuncName]> = Readonly<{
|
|
10
4
|
class: TClass;
|
|
11
5
|
func: TFunc;
|
|
@@ -34,38 +28,5 @@ export type TBoolFactoryOptions = Required<{
|
|
|
34
28
|
headers: Array<string>;
|
|
35
29
|
}>;
|
|
36
30
|
}>;
|
|
37
|
-
export declare const responseConverter: (response: Response) => Response;
|
|
38
|
-
export declare const controllerCreator: (controllerConstructor: new (...args: any[]) => unknown, group: RouterGroup, injector: Injector, prefix?: string) => RouterGroup;
|
|
39
|
-
export declare const argumentsResolution: (data: unknown, zodSchema: Zod.Schema, argumentIndex: number, funcName: string | symbol) => Promise<any>;
|
|
40
|
-
export declare const moduleResolution: (module: new (...args: any[]) => unknown, options: TBoolFactoryOptions) => Promise<Readonly<{
|
|
41
|
-
prefix: string | undefined;
|
|
42
|
-
injector: Injector;
|
|
43
|
-
startMiddlewareGroup: Readonly<{
|
|
44
|
-
class: IMiddleware<any, any>;
|
|
45
|
-
func: (...args: any[]) => any;
|
|
46
|
-
funcName: "start";
|
|
47
|
-
}>[];
|
|
48
|
-
endMiddlewareGroup: Readonly<{
|
|
49
|
-
class: IMiddleware<any, any>;
|
|
50
|
-
func: (...args: any[]) => any;
|
|
51
|
-
funcName: "end";
|
|
52
|
-
}>[];
|
|
53
|
-
guardGroup: Readonly<{
|
|
54
|
-
class: new (...args: any[]) => any;
|
|
55
|
-
funcName: "enforce";
|
|
56
|
-
func: any;
|
|
57
|
-
}>[];
|
|
58
|
-
openDispatcherGroup: Readonly<{
|
|
59
|
-
class: IDispatcher<any, any>;
|
|
60
|
-
func: (...args: any[]) => any;
|
|
61
|
-
funcName: "open";
|
|
62
|
-
}>[];
|
|
63
|
-
closeDispatcherGroup: Readonly<{
|
|
64
|
-
class: IDispatcher<any, any>;
|
|
65
|
-
func: (...args: any[]) => any;
|
|
66
|
-
funcName: "close";
|
|
67
|
-
}>[];
|
|
68
|
-
routerGroup: RouterGroup;
|
|
69
|
-
}> | undefined>;
|
|
70
31
|
export declare const BoolFactory: (modules: Object | Array<Object>, options: TBoolFactoryOptions) => Promise<void>;
|
|
71
32
|
export default BoolFactory;
|