@bool-ts/core 1.6.13 → 1.7.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 +11 -11
- package/LICENSE +21 -21
- package/__test/controller.ts +93 -79
- package/__test/dispatcher.ts +16 -0
- package/__test/firstGuard.ts +10 -10
- package/__test/firstMiddleware.ts +15 -9
- package/__test/index.ts +8 -8
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +28 -30
- package/__test/repository.ts +16 -16
- package/__test/secondGuard.ts +10 -10
- package/__test/secondMiddleware.ts +15 -9
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/arguments.d.ts +3 -3
- package/dist/decorators/arguments.js +3 -3
- package/dist/decorators/dispatcher.js +0 -3
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.js +1 -1
- package/dist/decorators/middleware.js +0 -3
- package/dist/decorators/module.d.ts +2 -4
- package/dist/decorators/module.js +5 -12
- package/dist/hooks/factory.d.ts +41 -2
- package/dist/hooks/factory.js +501 -406
- package/dist/hooks/injector.d.ts +14 -1
- package/dist/hooks/injector.js +3 -3
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -1
- package/dist/interfaces/dispatcher.d.ts +3 -2
- package/dist/interfaces/middleware.d.ts +3 -2
- package/dist/keys/index.d.ts +2 -1
- package/dist/keys/index.js +2 -1
- package/jsconfig.json +27 -27
- package/package.json +3 -3
- package/src/decorators/arguments.ts +286 -286
- package/src/decorators/controller.ts +21 -21
- package/src/decorators/dispatcher.ts +14 -18
- package/src/decorators/guard.ts +18 -18
- package/src/decorators/http.ts +81 -81
- package/src/decorators/index.ts +29 -29
- package/src/decorators/inject.ts +13 -13
- package/src/decorators/injectable.ts +8 -8
- package/src/decorators/middleware.ts +14 -18
- package/src/decorators/module.ts +84 -94
- package/src/decorators/zodSchema.ts +19 -19
- package/src/entities/index.ts +5 -5
- package/src/entities/route.ts +327 -327
- package/src/entities/router.ts +35 -35
- package/src/entities/routerGroup.ts +34 -34
- package/src/hooks/factory.ts +990 -806
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +57 -57
- package/src/http/clientError.ts +45 -45
- package/src/http/index.ts +62 -61
- package/src/http/serverError.ts +27 -27
- package/src/index.ts +9 -9
- package/src/interfaces/context.ts +4 -4
- package/src/interfaces/controller.ts +1 -1
- package/src/interfaces/dispatcher.ts +4 -3
- package/src/interfaces/guard.ts +3 -3
- package/src/interfaces/index.ts +6 -6
- package/src/interfaces/middleware.ts +4 -3
- package/src/interfaces/module.ts +1 -1
- package/src/keys/index.ts +23 -22
- package/test.http +31 -31
- package/tsconfig.json +108 -108
- package/__test/afterDispatcher.ts +0 -9
- package/__test/beforeDispatcher.ts +0 -9
package/src/decorators/guard.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { IGuard } from "../interfaces";
|
|
2
|
-
import { guardKey } from "../keys";
|
|
3
|
-
|
|
4
|
-
export type TGuardMetadata = undefined;
|
|
5
|
-
|
|
6
|
-
export const Guard =
|
|
7
|
-
() =>
|
|
8
|
-
<T extends { new (...args: any[]): IGuard }>(target: T) => {
|
|
9
|
-
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const metadata = undefined;
|
|
14
|
-
|
|
15
|
-
Reflect.defineMetadata(guardKey, metadata, target);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default Guard;
|
|
1
|
+
import type { IGuard } from "../interfaces";
|
|
2
|
+
import { guardKey } from "../keys";
|
|
3
|
+
|
|
4
|
+
export type TGuardMetadata = undefined;
|
|
5
|
+
|
|
6
|
+
export const Guard =
|
|
7
|
+
() =>
|
|
8
|
+
<T extends { new (...args: any[]): IGuard }>(target: T) => {
|
|
9
|
+
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const metadata = undefined;
|
|
14
|
+
|
|
15
|
+
Reflect.defineMetadata(guardKey, metadata, target);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default Guard;
|
package/src/decorators/http.ts
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import { controllerHttpKey } from "../keys";
|
|
2
|
-
|
|
3
|
-
export type TRoute = {
|
|
4
|
-
path: string;
|
|
5
|
-
httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
6
|
-
methodName: string;
|
|
7
|
-
descriptor: PropertyDescriptor;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type THttpMetadata = Array<TRoute>;
|
|
11
|
-
|
|
12
|
-
const defaultDecorator =
|
|
13
|
-
(path: string, method: "Get" | "Post" | "Put" | "Patch" | "Delete" | "Options") =>
|
|
14
|
-
(target: Object, methodName: string, descriptor: PropertyDescriptor) => {
|
|
15
|
-
if (!(descriptor.value instanceof Function)) {
|
|
16
|
-
throw Error(`${method} decorator only use for class method.`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const metadata: THttpMetadata = [
|
|
20
|
-
...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || []),
|
|
21
|
-
{
|
|
22
|
-
path: !path.startsWith("/") ? `/${path}` : path,
|
|
23
|
-
httpMethod: method.toUpperCase(),
|
|
24
|
-
methodName: methodName,
|
|
25
|
-
descriptor: descriptor
|
|
26
|
-
}
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
// Define controller metadata
|
|
30
|
-
Reflect.defineMetadata(controllerHttpKey, metadata, target.constructor);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @param path
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
export const Get = (path = "/") => defaultDecorator(path, "Get");
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @param path
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
export const Post = (path = "/") => defaultDecorator(path, "Post");
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param path
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
export const Put = (path = "/") => defaultDecorator(path, "Put");
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param path
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
export const Patch = (path = "/") => defaultDecorator(path, "Patch");
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
*
|
|
63
|
-
* @param path
|
|
64
|
-
* @returns
|
|
65
|
-
*/
|
|
66
|
-
export const Delete = (path = "/") => defaultDecorator(path, "Delete");
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
70
|
-
* @param path
|
|
71
|
-
* @returns
|
|
72
|
-
*/
|
|
73
|
-
export const Options = (path = "/") => defaultDecorator(path, "Options");
|
|
74
|
-
|
|
75
|
-
export default {
|
|
76
|
-
Get,
|
|
77
|
-
Post,
|
|
78
|
-
Put,
|
|
79
|
-
Patch,
|
|
80
|
-
Delete
|
|
81
|
-
};
|
|
1
|
+
import { controllerHttpKey } from "../keys";
|
|
2
|
+
|
|
3
|
+
export type TRoute = {
|
|
4
|
+
path: string;
|
|
5
|
+
httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
6
|
+
methodName: string;
|
|
7
|
+
descriptor: PropertyDescriptor;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type THttpMetadata = Array<TRoute>;
|
|
11
|
+
|
|
12
|
+
const defaultDecorator =
|
|
13
|
+
(path: string, method: "Get" | "Post" | "Put" | "Patch" | "Delete" | "Options") =>
|
|
14
|
+
(target: Object, methodName: string, descriptor: PropertyDescriptor) => {
|
|
15
|
+
if (!(descriptor.value instanceof Function)) {
|
|
16
|
+
throw Error(`${method} decorator only use for class method.`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const metadata: THttpMetadata = [
|
|
20
|
+
...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || []),
|
|
21
|
+
{
|
|
22
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
23
|
+
httpMethod: method.toUpperCase(),
|
|
24
|
+
methodName: methodName,
|
|
25
|
+
descriptor: descriptor
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// Define controller metadata
|
|
30
|
+
Reflect.defineMetadata(controllerHttpKey, metadata, target.constructor);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param path
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export const Get = (path = "/") => defaultDecorator(path, "Get");
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param path
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export const Post = (path = "/") => defaultDecorator(path, "Post");
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param path
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export const Put = (path = "/") => defaultDecorator(path, "Put");
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param path
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export const Patch = (path = "/") => defaultDecorator(path, "Patch");
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param path
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export const Delete = (path = "/") => defaultDecorator(path, "Delete");
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param path
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export const Options = (path = "/") => defaultDecorator(path, "Options");
|
|
74
|
+
|
|
75
|
+
export default {
|
|
76
|
+
Get,
|
|
77
|
+
Post,
|
|
78
|
+
Put,
|
|
79
|
+
Patch,
|
|
80
|
+
Delete
|
|
81
|
+
};
|
package/src/decorators/index.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
RequestHeader,
|
|
9
|
-
RequestHeaders,
|
|
10
|
-
ResponseHeaders,
|
|
11
|
-
RouteModel
|
|
12
|
-
} from "./arguments";
|
|
13
|
-
export { Controller } from "./controller";
|
|
14
|
-
export { Dispatcher } from "./dispatcher";
|
|
15
|
-
export { Guard } from "./guard";
|
|
16
|
-
export { Delete, Get, Options, Patch, Post, Put } from "./http";
|
|
17
|
-
export { Inject } from "./inject";
|
|
18
|
-
export { Injectable } from "./injectable";
|
|
19
|
-
export { Middleware } from "./middleware";
|
|
20
|
-
export { Module } from "./module";
|
|
21
|
-
export { ZodSchema } from "./zodSchema";
|
|
22
|
-
|
|
23
|
-
export type { TArgumentsMetadata } from "./arguments";
|
|
24
|
-
export type { TControllerMetadata } from "./controller";
|
|
25
|
-
export type { TDispatcherMetadata } from "./dispatcher";
|
|
26
|
-
export type { TGuardMetadata } from "./guard";
|
|
27
|
-
export type { THttpMetadata } from "./http";
|
|
28
|
-
export type { TMiddlewareMetadata } from "./middleware";
|
|
29
|
-
export type { TModuleMetadata, TModuleOptions } from "./module";
|
|
1
|
+
export {
|
|
2
|
+
Context,
|
|
3
|
+
Param,
|
|
4
|
+
Params,
|
|
5
|
+
Query,
|
|
6
|
+
Request,
|
|
7
|
+
RequestBody,
|
|
8
|
+
RequestHeader,
|
|
9
|
+
RequestHeaders,
|
|
10
|
+
ResponseHeaders,
|
|
11
|
+
RouteModel
|
|
12
|
+
} from "./arguments";
|
|
13
|
+
export { Controller } from "./controller";
|
|
14
|
+
export { Dispatcher } from "./dispatcher";
|
|
15
|
+
export { Guard } from "./guard";
|
|
16
|
+
export { Delete, Get, Options, Patch, Post, Put } from "./http";
|
|
17
|
+
export { Inject } from "./inject";
|
|
18
|
+
export { Injectable } from "./injectable";
|
|
19
|
+
export { Middleware } from "./middleware";
|
|
20
|
+
export { Module } from "./module";
|
|
21
|
+
export { ZodSchema } from "./zodSchema";
|
|
22
|
+
|
|
23
|
+
export type { TArgumentsMetadata } from "./arguments";
|
|
24
|
+
export type { TControllerMetadata } from "./controller";
|
|
25
|
+
export type { TDispatcherMetadata } from "./dispatcher";
|
|
26
|
+
export type { TGuardMetadata } from "./guard";
|
|
27
|
+
export type { THttpMetadata } from "./http";
|
|
28
|
+
export type { TMiddlewareMetadata } from "./middleware";
|
|
29
|
+
export type { TModuleMetadata, TModuleOptions } from "./module";
|
package/src/decorators/inject.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { injectKey } from "../keys";
|
|
2
|
-
|
|
3
|
-
export const Inject = <T extends Object>(definition: { new (...args: any[]): T } | string | symbol) => {
|
|
4
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
5
|
-
const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target) || [];
|
|
6
|
-
|
|
7
|
-
designParameterTypes[parameterIndex] = definition;
|
|
8
|
-
|
|
9
|
-
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default Inject;
|
|
1
|
+
import { injectKey } from "../keys";
|
|
2
|
+
|
|
3
|
+
export const Inject = <T extends Object>(definition: { new (...args: any[]): T } | string | symbol) => {
|
|
4
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
5
|
+
const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target) || [];
|
|
6
|
+
|
|
7
|
+
designParameterTypes[parameterIndex] = definition;
|
|
8
|
+
|
|
9
|
+
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default Inject;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { injectableKey } from "../keys";
|
|
2
|
-
|
|
3
|
-
export const Injectable =
|
|
4
|
-
() =>
|
|
5
|
-
<T extends Object>(target: T) =>
|
|
6
|
-
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
7
|
-
|
|
8
|
-
export default Injectable;
|
|
1
|
+
import { injectableKey } from "../keys";
|
|
2
|
+
|
|
3
|
+
export const Injectable =
|
|
4
|
+
() =>
|
|
5
|
+
<T extends Object>(target: T) =>
|
|
6
|
+
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
7
|
+
|
|
8
|
+
export default Injectable;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import type { IMiddleware } from "../interfaces";
|
|
2
|
-
import { middlewareKey } from "../keys";
|
|
3
|
-
|
|
4
|
-
export type TMiddlewareMetadata = undefined;
|
|
5
|
-
|
|
6
|
-
export const Middleware =
|
|
7
|
-
() =>
|
|
8
|
-
<T extends { new (...args: any[]): IMiddleware }>(target: T) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Reflect.defineMetadata(middlewareKey, metadata, target);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default Middleware;
|
|
1
|
+
import type { IMiddleware } from "../interfaces";
|
|
2
|
+
import { middlewareKey } from "../keys";
|
|
3
|
+
|
|
4
|
+
export type TMiddlewareMetadata = undefined;
|
|
5
|
+
|
|
6
|
+
export const Middleware =
|
|
7
|
+
() =>
|
|
8
|
+
<T extends { new (...args: any[]): IMiddleware }>(target: T) => {
|
|
9
|
+
const metadata: TMiddlewareMetadata = undefined;
|
|
10
|
+
|
|
11
|
+
Reflect.defineMetadata(middlewareKey, metadata, target);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default Middleware;
|
package/src/decorators/module.ts
CHANGED
|
@@ -1,94 +1,84 @@
|
|
|
1
|
-
import type { IModule } from "../interfaces/module";
|
|
2
|
-
import { controllerKey, dispatcherKey, guardKey, injectableKey, middlewareKey, moduleKey } from "../keys";
|
|
3
|
-
|
|
4
|
-
type TInstances = Array<new (...args: any[]) => any>;
|
|
5
|
-
type TLoaders<TConfig extends {} = {}> = Record<
|
|
6
|
-
string | symbol,
|
|
7
|
-
(args: { config: TConfig }) => [string | symbol, any] | Promise<[string | symbol, any]>
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
export type TModuleOptions<TConfig extends {} = {}> =
|
|
11
|
-
| Partial<{
|
|
12
|
-
config: TConfig | (() => TConfig | Promise<TConfig>);
|
|
13
|
-
prefix: string;
|
|
14
|
-
dependencies: TInstances;
|
|
15
|
-
loaders: TLoaders<TConfig>;
|
|
16
|
-
middlewares: TInstances;
|
|
17
|
-
guards: TInstances;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!Reflect.getOwnMetadataKeys(dependencies[i]).includes(injectableKey)) {
|
|
86
|
-
throw Error(`${dependencies[i].name} is not an injectable.`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
Reflect.defineMetadata(moduleKey, args, target);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export default Module;
|
|
1
|
+
import type { IModule } from "../interfaces/module";
|
|
2
|
+
import { controllerKey, dispatcherKey, guardKey, injectableKey, middlewareKey, moduleKey } from "../keys";
|
|
3
|
+
|
|
4
|
+
type TInstances = Array<new (...args: any[]) => any>;
|
|
5
|
+
type TLoaders<TConfig extends {} = {}> = Record<
|
|
6
|
+
string | symbol,
|
|
7
|
+
(args: { config: TConfig }) => [string | symbol, any] | Promise<[string | symbol, any]>
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
export type TModuleOptions<TConfig extends {} = {}> =
|
|
11
|
+
| Partial<{
|
|
12
|
+
config: TConfig | (() => TConfig | Promise<TConfig>);
|
|
13
|
+
prefix: string;
|
|
14
|
+
dependencies: TInstances;
|
|
15
|
+
loaders: TLoaders<TConfig>;
|
|
16
|
+
middlewares: TInstances;
|
|
17
|
+
guards: TInstances;
|
|
18
|
+
controllers: TInstances;
|
|
19
|
+
dispatchers: TInstances;
|
|
20
|
+
}>
|
|
21
|
+
| undefined;
|
|
22
|
+
|
|
23
|
+
export type TModuleMetadata<TConfig extends {} = {}> =
|
|
24
|
+
| Partial<{
|
|
25
|
+
config: TConfig | ((...args: any[]) => TConfig | Promise<TConfig>);
|
|
26
|
+
prefix: string;
|
|
27
|
+
dependencies: TInstances;
|
|
28
|
+
loaders: TLoaders<TConfig>;
|
|
29
|
+
middlewares: TInstances;
|
|
30
|
+
guards: TInstances;
|
|
31
|
+
controllers: TInstances;
|
|
32
|
+
dispatchers: TInstances;
|
|
33
|
+
}>
|
|
34
|
+
| undefined;
|
|
35
|
+
|
|
36
|
+
export const Module =
|
|
37
|
+
<TConfig extends {} = {}>(args?: TModuleOptions<TConfig>) =>
|
|
38
|
+
<T extends { new (...args: any[]): IModule }>(target: T) => {
|
|
39
|
+
const { middlewares, guards, dispatchers, controllers, dependencies } = args || {};
|
|
40
|
+
|
|
41
|
+
if (middlewares) {
|
|
42
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
43
|
+
if (!Reflect.getOwnMetadataKeys(middlewares[i]).includes(middlewareKey)) {
|
|
44
|
+
throw Error(`${middlewares[i].name} is not a middleware.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (guards) {
|
|
50
|
+
for (let i = 0; i < guards.length; i++) {
|
|
51
|
+
if (!Reflect.getOwnMetadataKeys(guards[i]).includes(guardKey)) {
|
|
52
|
+
throw Error(`${guards[i].name} is not a guard.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (dispatchers) {
|
|
58
|
+
for (let i = 0; i < dispatchers.length; i++) {
|
|
59
|
+
if (!Reflect.getOwnMetadataKeys(dispatchers[i]).includes(dispatcherKey)) {
|
|
60
|
+
throw Error(`${dispatchers[i].name} is not a dispatcher.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (controllers) {
|
|
66
|
+
for (let i = 0; i < controllers.length; i++) {
|
|
67
|
+
if (!Reflect.getOwnMetadataKeys(controllers[i]).includes(controllerKey)) {
|
|
68
|
+
throw Error(`${controllers[i].name} is not a controller.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (dependencies) {
|
|
74
|
+
for (let i = 0; i < dependencies.length; i++) {
|
|
75
|
+
if (!Reflect.getOwnMetadataKeys(dependencies[i]).includes(injectableKey)) {
|
|
76
|
+
throw Error(`${dependencies[i].name} is not an injectable.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Reflect.defineMetadata(moduleKey, args, target);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default Module;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
|
-
import { controllerRouteZodSchemaKey } from "../keys";
|
|
3
|
-
|
|
4
|
-
export const ZodSchema = (schema: Zod.Schema) => {
|
|
5
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
6
|
-
if (!methodName) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const zodSchemasMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName) || {};
|
|
11
|
-
|
|
12
|
-
zodSchemasMetadata[`paramterIndexes.${parameterIndex}`] = {
|
|
13
|
-
index: parameterIndex,
|
|
14
|
-
schema: schema
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
Reflect.defineMetadata(controllerRouteZodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
1
|
+
import * as Zod from "zod";
|
|
2
|
+
import { controllerRouteZodSchemaKey } from "../keys";
|
|
3
|
+
|
|
4
|
+
export const ZodSchema = (schema: Zod.Schema) => {
|
|
5
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
6
|
+
if (!methodName) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const zodSchemasMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName) || {};
|
|
11
|
+
|
|
12
|
+
zodSchemasMetadata[`paramterIndexes.${parameterIndex}`] = {
|
|
13
|
+
index: parameterIndex,
|
|
14
|
+
schema: schema
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
Reflect.defineMetadata(controllerRouteZodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
|
|
18
|
+
};
|
|
19
|
+
};
|
package/src/entities/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { TRouteModel } from "./route";
|
|
2
|
-
|
|
3
|
-
export { Route } from "./route";
|
|
4
|
-
export { Router } from "./router";
|
|
5
|
-
export { RouterGroup } from "./routerGroup";
|
|
1
|
+
export type { TRouteModel } from "./route";
|
|
2
|
+
|
|
3
|
+
export { Route } from "./route";
|
|
4
|
+
export { Router } from "./router";
|
|
5
|
+
export { RouterGroup } from "./routerGroup";
|