@bool-ts/core 1.4.1 → 1.5.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/afterDispatcher.ts +9 -0
- package/__test/beforeDispatcher.ts +9 -0
- package/__test/controller.ts +66 -66
- package/__test/firstGuard.ts +10 -0
- package/__test/firstMiddleware.ts +9 -0
- package/__test/index.ts +8 -8
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +25 -16
- package/__test/repository.ts +16 -16
- package/__test/secondGuard.ts +10 -0
- package/__test/secondMiddleware.ts +9 -0
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/arguments.d.ts +12 -6
- package/dist/decorators/arguments.js +39 -26
- package/dist/decorators/controller.d.ts +9 -1
- package/dist/decorators/controller.js +6 -4
- package/dist/decorators/dispatcher.d.ts +7 -0
- package/dist/decorators/dispatcher.js +9 -0
- package/dist/decorators/guard.d.ts +7 -0
- package/dist/decorators/guard.js +9 -0
- package/dist/decorators/http.d.ts +4 -3
- package/dist/decorators/http.js +6 -5
- package/dist/decorators/index.d.ts +13 -3
- package/dist/decorators/index.js +5 -2
- package/dist/decorators/injectable.d.ts +1 -1
- package/dist/decorators/injectable.js +1 -4
- package/dist/decorators/middleware.d.ts +7 -0
- package/dist/decorators/middleware.js +9 -0
- package/dist/decorators/module.d.ts +28 -7
- package/dist/decorators/module.js +48 -1
- package/dist/entities/route.d.ts +5 -5
- package/dist/entities/routerGroup.d.ts +1 -1
- package/dist/hooks/factory.d.ts +3 -3
- package/dist/hooks/factory.js +282 -60
- package/dist/hooks/injector.js +6 -5
- package/dist/interfaces/index.d.ts +5 -2
- package/dist/interfaces/index.js +1 -1
- package/package.json +1 -1
- package/src/decorators/arguments.ts +214 -186
- package/src/decorators/controller.ts +22 -14
- package/src/decorators/dispatcher.ts +19 -0
- package/src/decorators/guard.ts +19 -0
- package/src/decorators/http.ts +81 -81
- package/src/decorators/index.ts +28 -7
- package/src/decorators/inject.ts +13 -13
- package/src/decorators/injectable.ts +8 -11
- package/src/decorators/middleware.ts +19 -0
- package/src/decorators/module.ts +100 -21
- package/src/decorators/zodSchema.ts +20 -20
- package/src/entities/index.ts +3 -3
- package/src/entities/route.ts +328 -328
- package/src/entities/router.ts +35 -35
- package/src/entities/routerGroup.ts +34 -34
- package/src/hooks/factory.ts +653 -319
- 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 +63 -63
- package/src/http/serverError.ts +38 -38
- package/src/index.ts +6 -6
- package/src/interfaces/controller.d.ts +1 -0
- package/src/interfaces/dispatcher.d.ts +3 -0
- package/src/interfaces/guard.d.ts +3 -0
- package/src/interfaces/index.ts +5 -3
- package/src/interfaces/middleware.d.ts +3 -0
- package/src/interfaces/module.d.ts +1 -0
- package/test.http +31 -30
- package/tsconfig.json +107 -107
package/src/decorators/index.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export {
|
|
2
|
+
RequestHeaders,
|
|
3
|
+
Body,
|
|
4
|
+
Params,
|
|
5
|
+
Param,
|
|
6
|
+
Query,
|
|
7
|
+
Request,
|
|
8
|
+
ResponseHeaders,
|
|
9
|
+
EArgumentTypes,
|
|
10
|
+
argumentsKey
|
|
11
|
+
} from "./arguments";
|
|
12
|
+
export { Controller, controllerKey } from "./controller";
|
|
13
|
+
export { Guard, guardKey } from "./guard";
|
|
14
|
+
export { Inject, injectKey } from "./inject";
|
|
15
|
+
export { Injectable, injectableKey } from "./injectable";
|
|
16
|
+
export { Middleware, middlewareKey } from "./middleware";
|
|
17
|
+
export { Module, moduleKey } from "./module";
|
|
18
|
+
export { Get, Post, Put, Patch, Delete, Options, controllerHttpKey } from "./http";
|
|
19
|
+
export { ZodSchema, controllerRouteZodSchemaKey } from "./zodSchema";
|
|
20
|
+
export { Dispatcher, dispatcherKey } from "./dispatcher";
|
|
21
|
+
|
|
22
|
+
export type { TControllerMetadata } from "./controller";
|
|
23
|
+
export type { TModuleMetadata, TModuleOptions } from "./module";
|
|
24
|
+
export type { THttpMetadata } from "./http";
|
|
25
|
+
export type { TArgumentsMetadata } from "./arguments";
|
|
26
|
+
export type { TMiddlewareMetadata } from "./middleware";
|
|
27
|
+
export type { TGuardMetadata } from "./guard";
|
|
28
|
+
export type { TDispatcherMetadata } from "./dispatcher";
|
package/src/decorators/inject.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export const injectKey = "design:paramtypes";
|
|
2
|
-
|
|
3
|
-
export const Inject = <T extends Object>(classDefinition: { new (...args: any[]): T }) => {
|
|
4
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
5
|
-
const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target) || [];
|
|
6
|
-
|
|
7
|
-
designParameterTypes[parameterIndex] = classDefinition;
|
|
8
|
-
|
|
9
|
-
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default Inject;
|
|
1
|
+
export const injectKey = "design:paramtypes";
|
|
2
|
+
|
|
3
|
+
export const Inject = <T extends Object>(classDefinition: { new (...args: any[]): T }) => {
|
|
4
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
5
|
+
const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target) || [];
|
|
6
|
+
|
|
7
|
+
designParameterTypes[parameterIndex] = classDefinition;
|
|
8
|
+
|
|
9
|
+
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default Inject;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export const injectableKey = Symbol.for("__bool:injectable__");
|
|
2
|
-
|
|
3
|
-
export const Injectable =
|
|
4
|
-
() =>
|
|
5
|
-
<T extends Object>(target: T) =>
|
|
6
|
-
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default Injectable;
|
|
1
|
+
export const injectableKey = Symbol.for("__bool:injectable__");
|
|
2
|
+
|
|
3
|
+
export const Injectable =
|
|
4
|
+
() =>
|
|
5
|
+
<T extends Object>(target: T) =>
|
|
6
|
+
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
7
|
+
|
|
8
|
+
export default Injectable;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IMiddleware } from "../interfaces";
|
|
2
|
+
|
|
3
|
+
export type TMiddlewareMetadata = undefined;
|
|
4
|
+
|
|
5
|
+
export const middlewareKey = Symbol.for("__bool:middleware__");
|
|
6
|
+
|
|
7
|
+
export const Middleware =
|
|
8
|
+
() =>
|
|
9
|
+
<T extends { new (...args: any[]): IMiddleware }>(target: T) => {
|
|
10
|
+
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const metadata: TMiddlewareMetadata = undefined;
|
|
15
|
+
|
|
16
|
+
Reflect.defineMetadata(middlewareKey, metadata, target);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default Middleware;
|
package/src/decorators/module.ts
CHANGED
|
@@ -1,21 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import type { IModule } from "../interfaces/module";
|
|
2
|
+
import { controllerKey } from "./controller";
|
|
3
|
+
import { dispatcherKey } from "./dispatcher";
|
|
4
|
+
import { guardKey } from "./guard";
|
|
5
|
+
import { injectableKey } from "./injectable";
|
|
6
|
+
import { middlewareKey } from "./middleware";
|
|
7
|
+
|
|
8
|
+
type TInstances = Array<new (...args: any[]) => any>;
|
|
9
|
+
|
|
10
|
+
export type TModuleOptions =
|
|
11
|
+
| Partial<{
|
|
12
|
+
options: Partial<{
|
|
13
|
+
prefix: string;
|
|
14
|
+
allowOrigins: string | Array<string>;
|
|
15
|
+
allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
|
|
16
|
+
}>;
|
|
17
|
+
dependencies: TInstances;
|
|
18
|
+
controllers: TInstances;
|
|
19
|
+
middlewares: TInstances;
|
|
20
|
+
guards: TInstances;
|
|
21
|
+
beforeDispatchers: TInstances;
|
|
22
|
+
afterDispatchers: TInstances;
|
|
23
|
+
}>
|
|
24
|
+
| undefined;
|
|
25
|
+
|
|
26
|
+
export type TModuleMetadata =
|
|
27
|
+
| Partial<{
|
|
28
|
+
options: Partial<{
|
|
29
|
+
prefix: string;
|
|
30
|
+
allowOrigins: string | Array<string>;
|
|
31
|
+
allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
|
|
32
|
+
}>;
|
|
33
|
+
controllers: TInstances;
|
|
34
|
+
dependencies: TInstances;
|
|
35
|
+
middlewares: TInstances;
|
|
36
|
+
guards: TInstances;
|
|
37
|
+
beforeDispatchers: TInstances;
|
|
38
|
+
afterDispatchers: TInstances;
|
|
39
|
+
}>
|
|
40
|
+
| undefined;
|
|
41
|
+
|
|
42
|
+
export const moduleKey = Symbol.for("__bool:module__");
|
|
43
|
+
|
|
44
|
+
export const Module =
|
|
45
|
+
(args?: TModuleOptions) =>
|
|
46
|
+
<T extends { new (...args: any[]): IModule }>(target: T) => {
|
|
47
|
+
const { middlewares, guards, beforeDispatchers, controllers, afterDispatchers, dependencies } = args || {};
|
|
48
|
+
|
|
49
|
+
if (middlewares) {
|
|
50
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
51
|
+
if (!Reflect.getOwnMetadataKeys(middlewares[i]).includes(middlewareKey)) {
|
|
52
|
+
throw Error(`${middlewares[i].name} is not a middleware.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (guards) {
|
|
58
|
+
for (let i = 0; i < guards.length; i++) {
|
|
59
|
+
if (!Reflect.getOwnMetadataKeys(guards[i]).includes(guardKey)) {
|
|
60
|
+
throw Error(`${guards[i].name} is not a guard.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (beforeDispatchers) {
|
|
66
|
+
for (let i = 0; i < beforeDispatchers.length; i++) {
|
|
67
|
+
if (!Reflect.getOwnMetadataKeys(beforeDispatchers[i]).includes(dispatcherKey)) {
|
|
68
|
+
throw Error(`${beforeDispatchers[i].name} is not a dispatcher.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (controllers) {
|
|
74
|
+
for (let i = 0; i < controllers.length; i++) {
|
|
75
|
+
if (!Reflect.getOwnMetadataKeys(controllers[i]).includes(controllerKey)) {
|
|
76
|
+
throw Error(`${controllers[i].name} is not a controller.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (afterDispatchers) {
|
|
82
|
+
for (let i = 0; i < afterDispatchers.length; i++) {
|
|
83
|
+
if (!Reflect.getOwnMetadataKeys(afterDispatchers[i]).includes(dispatcherKey)) {
|
|
84
|
+
throw Error(`${afterDispatchers[i].name} is not a dispatcher.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (dependencies) {
|
|
90
|
+
for (let i = 0; i < dependencies.length; i++) {
|
|
91
|
+
if (!Reflect.getOwnMetadataKeys(dependencies[i]).includes(injectableKey)) {
|
|
92
|
+
throw Error(`${dependencies[i].name} is not an injectable.`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
Reflect.defineMetadata(moduleKey, args, target);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default Module;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
|
-
|
|
3
|
-
export const controllerRouteZodSchemaKey = Symbol.for("__bool:controller.route.zodSchema__");
|
|
4
|
-
|
|
5
|
-
export const ZodSchema = (schema: Zod.Schema) => {
|
|
6
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
7
|
-
if (!methodName) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const zodSchemasMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName) || {};
|
|
12
|
-
|
|
13
|
-
zodSchemasMetadata[`paramterIndexes.${parameterIndex}`] = {
|
|
14
|
-
index: parameterIndex,
|
|
15
|
-
schema: schema
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Reflect.defineMetadata(controllerRouteZodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
|
|
19
|
-
};
|
|
20
|
-
};
|
|
1
|
+
import * as Zod from "zod";
|
|
2
|
+
|
|
3
|
+
export const controllerRouteZodSchemaKey = Symbol.for("__bool:controller.route.zodSchema__");
|
|
4
|
+
|
|
5
|
+
export const ZodSchema = (schema: Zod.Schema) => {
|
|
6
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
7
|
+
if (!methodName) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const zodSchemasMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName) || {};
|
|
12
|
+
|
|
13
|
+
zodSchemasMetadata[`paramterIndexes.${parameterIndex}`] = {
|
|
14
|
+
index: parameterIndex,
|
|
15
|
+
schema: schema
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Reflect.defineMetadata(controllerRouteZodSchemaKey, zodSchemasMetadata, target.constructor, methodName);
|
|
19
|
+
};
|
|
20
|
+
};
|
package/src/entities/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Route } from "./route";
|
|
2
|
-
export { Router } from "./router";
|
|
3
|
-
export { RouterGroup } from "./routerGroup";
|
|
1
|
+
export { Route } from "./route";
|
|
2
|
+
export { Router } from "./router";
|
|
3
|
+
export { RouterGroup } from "./routerGroup";
|