@bool-ts/core 1.3.2 → 1.4.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.
Files changed (68) hide show
  1. package/.prettierrc +11 -0
  2. package/LICENSE +21 -21
  3. package/__test/controller.ts +66 -79
  4. package/__test/index.ts +8 -11
  5. package/__test/interfaces.ts +7 -7
  6. package/__test/module.ts +16 -17
  7. package/__test/repository.ts +16 -16
  8. package/__test/service.ts +20 -20
  9. package/bun.lockb +0 -0
  10. package/dist/decorators/arguments.d.ts +31 -0
  11. package/dist/decorators/arguments.js +67 -0
  12. package/dist/decorators/controller.d.ts +2 -2
  13. package/dist/decorators/controller.js +6 -10
  14. package/dist/decorators/http.d.ts +1 -1
  15. package/dist/decorators/http.js +16 -103
  16. package/dist/decorators/index.d.ts +1 -0
  17. package/dist/decorators/index.js +7 -26
  18. package/dist/decorators/inject.js +5 -9
  19. package/dist/decorators/injectable.d.ts +2 -2
  20. package/dist/decorators/injectable.js +4 -8
  21. package/dist/decorators/module.d.ts +4 -2
  22. package/dist/decorators/module.js +4 -8
  23. package/dist/decorators/zodSchema.d.ts +1 -1
  24. package/dist/decorators/zodSchema.js +5 -8
  25. package/dist/entities/index.d.ts +3 -0
  26. package/dist/entities/index.js +3 -0
  27. package/dist/entities/route.d.ts +101 -0
  28. package/dist/entities/route.js +257 -0
  29. package/dist/entities/router.d.ts +10 -0
  30. package/dist/entities/router.js +25 -0
  31. package/dist/entities/routerGroup.d.ts +14 -0
  32. package/dist/entities/routerGroup.js +24 -0
  33. package/dist/hooks/factory.d.ts +12 -12
  34. package/dist/hooks/factory.js +180 -151
  35. package/dist/hooks/index.js +2 -7
  36. package/dist/hooks/injector.js +7 -10
  37. package/dist/http/clientError.d.ts +1 -1
  38. package/dist/http/clientError.js +3 -7
  39. package/dist/http/index.d.ts +12 -2
  40. package/dist/http/index.js +34 -73
  41. package/dist/http/serverError.js +3 -7
  42. package/dist/index.js +5 -21
  43. package/dist/interfaces/index.js +1 -3
  44. package/dist/ultils/asyncFunction.js +1 -4
  45. package/dist/ultils/index.js +1 -17
  46. package/package.json +30 -33
  47. package/src/decorators/arguments.ts +128 -0
  48. package/src/decorators/controller.ts +14 -18
  49. package/src/decorators/http.ts +81 -195
  50. package/src/decorators/index.ts +7 -6
  51. package/src/decorators/inject.ts +13 -19
  52. package/src/decorators/injectable.ts +11 -12
  53. package/src/decorators/module.ts +21 -22
  54. package/src/decorators/zodSchema.ts +20 -27
  55. package/src/entities/index.ts +3 -0
  56. package/src/entities/route.ts +328 -0
  57. package/src/entities/router.ts +35 -0
  58. package/src/entities/routerGroup.ts +34 -0
  59. package/src/hooks/factory.ts +285 -205
  60. package/src/hooks/index.ts +2 -2
  61. package/src/hooks/injector.ts +43 -43
  62. package/src/http/clientError.ts +45 -56
  63. package/src/http/index.ts +63 -72
  64. package/src/http/serverError.ts +38 -38
  65. package/src/index.ts +6 -6
  66. package/src/interfaces/index.ts +3 -3
  67. package/test.http +30 -28
  68. package/tsconfig.json +107 -109
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./asyncFunction"), exports);
1
+ export * from "./asyncFunction";
package/package.json CHANGED
@@ -1,34 +1,31 @@
1
1
  {
2
- "name": "@bool-ts/core",
3
- "version": "1.3.2",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "test": "bun --hot run __test/index.ts",
8
- "build": "tsc"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/BoolTS/core.git"
13
- },
14
- "author": "Trần Đức Tâm (Neo)",
15
- "license": "MIT",
16
- "bugs": {
17
- "url": "https://github.com/BoolTS/core/issues"
18
- },
19
- "homepage": "https://github.com/BoolTS/core#readme",
20
- "dependencies": {
21
- "colors": "^1.4.0",
22
- "express": "^5.0.0-beta.3",
23
- "qs": "^6.12.1",
24
- "reflect-metadata": "^0.2.2",
25
- "response-time": "^2.3.2",
26
- "zod": "^3.23.8"
27
- },
28
- "devDependencies": {
29
- "@types/express": "^4.17.21",
30
- "@types/node-statsd": "^0.1.6",
31
- "@types/response-time": "^2.3.8",
32
- "typescript": "^5.4.5"
33
- }
34
- }
2
+ "name": "@bool-ts/core",
3
+ "version": "1.4.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "bun --hot run __test/index.ts",
8
+ "build": "tsc"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/BoolTS/core.git"
13
+ },
14
+ "author": "Trần Đức Tâm (Neo)",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/BoolTS/core/issues"
18
+ },
19
+ "homepage": "https://github.com/BoolTS/core#readme",
20
+ "dependencies": {
21
+ "colors": "^1.4.0",
22
+ "qs": "^6.13.0",
23
+ "reflect-metadata": "^0.2.2",
24
+ "zod": "^3.23.8"
25
+ },
26
+ "devDependencies": {
27
+ "@types/bun": "^1.1.6",
28
+ "@types/qs": "^6.9.15",
29
+ "typescript": "^5.5.4"
30
+ }
31
+ }
@@ -0,0 +1,128 @@
1
+ import * as Zod from "zod";
2
+
3
+ export enum EArgumentTypes {
4
+ headers = "HEADERS",
5
+ body = "BODY",
6
+ params = "PARAMS",
7
+ query = "QUERY"
8
+ }
9
+
10
+ export type TMetadata =
11
+ | {
12
+ index: number;
13
+ type: EArgumentTypes.headers;
14
+ zodSchema?: Zod.Schema;
15
+ }
16
+ | {
17
+ index: number;
18
+ type: EArgumentTypes.body;
19
+ zodSchema?: Zod.Schema;
20
+ parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
21
+ }
22
+ | {
23
+ index: number;
24
+ type: EArgumentTypes.params;
25
+ key?: string;
26
+ zodSchema?: Zod.Schema;
27
+ }
28
+ | {
29
+ index: number;
30
+ type: EArgumentTypes.query;
31
+ zodSchema?: Zod.Schema;
32
+ };
33
+
34
+ export const controllerActionArgumentsKey = Symbol.for("__bool:controller.action::arguments__");
35
+
36
+ export const Headers = (zodSchema?: Zod.Schema) => {
37
+ return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
38
+ if (!methodName) {
39
+ return;
40
+ }
41
+
42
+ const headersMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
43
+
44
+ headersMetadata[`argumentIndexes.${parameterIndex}`] = {
45
+ index: parameterIndex,
46
+ type: EArgumentTypes.headers,
47
+ zodSchema: zodSchema
48
+ } satisfies Extract<
49
+ TMetadata,
50
+ {
51
+ type: EArgumentTypes.headers;
52
+ }
53
+ >;
54
+
55
+ Reflect.defineMetadata(controllerActionArgumentsKey, headersMetadata, target.constructor, methodName);
56
+ };
57
+ };
58
+
59
+ export const Body = (zodSchema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") => {
60
+ return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
61
+ if (!methodName) {
62
+ return;
63
+ }
64
+
65
+ const bodyMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
66
+
67
+ bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
68
+ index: parameterIndex,
69
+ type: EArgumentTypes.body,
70
+ zodSchema: zodSchema,
71
+ parser: parser
72
+ } satisfies Extract<
73
+ TMetadata,
74
+ {
75
+ type: EArgumentTypes.body;
76
+ }
77
+ >;
78
+
79
+ Reflect.defineMetadata(controllerActionArgumentsKey, bodyMetadata, target.constructor, methodName);
80
+ };
81
+ };
82
+
83
+ export const Params = (key?: string, zodSchema?: Zod.Schema) => {
84
+ return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
85
+ if (!methodName) {
86
+ return;
87
+ }
88
+
89
+ const paramsMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
90
+
91
+ paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
92
+ index: parameterIndex,
93
+ type: EArgumentTypes.params,
94
+ key: key,
95
+ zodSchema: zodSchema
96
+ } satisfies Extract<
97
+ TMetadata,
98
+ {
99
+ type: EArgumentTypes.params;
100
+ }
101
+ >;
102
+
103
+ Reflect.defineMetadata(controllerActionArgumentsKey, paramsMetadata, target.constructor, methodName);
104
+ };
105
+ };
106
+
107
+ export const Query = (zodSchema?: Zod.Schema) => {
108
+ return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
109
+ if (!methodName) {
110
+ return;
111
+ }
112
+
113
+ const queryMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
114
+
115
+ queryMetadata[`argumentIndexes.${parameterIndex}`] = {
116
+ index: parameterIndex,
117
+ type: EArgumentTypes.params,
118
+ zodSchema: zodSchema
119
+ } satisfies Extract<
120
+ TMetadata,
121
+ {
122
+ type: EArgumentTypes.params;
123
+ }
124
+ >;
125
+
126
+ Reflect.defineMetadata(controllerActionArgumentsKey, queryMetadata, target.constructor, methodName);
127
+ };
128
+ };
@@ -1,18 +1,14 @@
1
- import { injectableKey } from "./injectable";
2
-
3
-
4
- export const controllerKey = "__bool:controller__";
5
-
6
- export const Controller = (
7
- prefix: string
8
- ) => <T extends Object>(
9
- target: T,
10
- context?: ClassDecoratorContext
11
- ) => {
12
- Reflect.defineMetadata(controllerKey, !prefix.startsWith("/") ? `/${prefix}` : prefix, target);
13
- Reflect.defineMetadata(injectableKey, undefined, target);
14
-
15
- return target;
16
- }
17
-
18
- export default Controller;
1
+ import { injectableKey } from "./injectable";
2
+
3
+ export const controllerKey = Symbol.for("__bool:controller__");
4
+
5
+ export const Controller =
6
+ (prefix: string) =>
7
+ <T extends Object>(target: T) => {
8
+ Reflect.defineMetadata(controllerKey, !prefix.startsWith("/") ? `/${prefix}` : prefix, target);
9
+ Reflect.defineMetadata(injectableKey, undefined, target);
10
+
11
+ return target;
12
+ };
13
+
14
+ export default Controller;
@@ -1,195 +1,81 @@
1
- import { HttpClientError, HttpServerError } from "../http";
2
- import { AsyncFunction } from "../ultils";
3
- import { controllerRouteZodSchemaKey } from "./zodSchema";
4
-
5
- export interface IControllerRoute {
6
- path: string;
7
- httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
8
- methodName: string;
9
- descriptor: PropertyDescriptor;
10
- }
11
-
12
-
13
- export const controllerRoutesKey = "__bool:controller.routes__";
14
-
15
-
16
- const defaultDecorator = (
17
- path: string,
18
- method: "Get" | "Post" | "Put" | "Patch" | "Delete" | "Options"
19
- ) => (
20
- target: Object,
21
- methodName: string,
22
- descriptor: PropertyDescriptor
23
- ) => {
24
- if (!(descriptor.value instanceof Function)) {
25
- throw Error(`${method} decorator only use for method.`);
26
- }
27
-
28
- // Define controller metadata
29
- Reflect.defineMetadata(controllerRoutesKey, [
30
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
31
- {
32
- path: !path.startsWith("/") ? `/${path}` : path,
33
- httpMethod: method.toUpperCase(),
34
- methodName: methodName,
35
- descriptor: descriptor
36
- }
37
- ], target.constructor);
38
-
39
- // Define route parameters zod validation
40
- const currentMethod = descriptor.value;
41
- const isAsync = descriptor.value instanceof AsyncFunction;
42
-
43
- if (!isAsync) {
44
- descriptor.value = function () {
45
- const zodSchemaMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName);
46
-
47
- if (zodSchemaMetadata) {
48
- for (const zodSchemaProp in zodSchemaMetadata) {
49
- const tmpZodMetadata = zodSchemaMetadata[zodSchemaProp];
50
-
51
- try {
52
- const validation = tmpZodMetadata.schema.safeParse(arguments[tmpZodMetadata.index]);
53
-
54
- if (!validation.success) {
55
- throw new HttpClientError({
56
- httpCode: 400,
57
- message: `Validation at the [${methodName}] method fails at positional argument [${tmpZodMetadata.index}].`,
58
- data: validation.error.issues
59
- });
60
- }
61
-
62
- arguments[tmpZodMetadata.index] = validation.data;
63
- }
64
- catch (error) {
65
- if (error instanceof HttpClientError) {
66
- throw error;
67
- }
68
-
69
- throw new HttpServerError({
70
- httpCode: 500,
71
- message: `Validation at the [${methodName}] method error at positional argument [${tmpZodMetadata.index}].`,
72
- data: !(error instanceof Error) ? error : [{
73
- message: error.message,
74
- code: error.name,
75
- cause: error.cause
76
- }]
77
- });
78
- }
79
- }
80
- }
81
-
82
- return currentMethod.apply(this, arguments);
83
- }
84
- }
85
- else {
86
- descriptor.value = async function () {
87
- const zodSchemaMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName);
88
-
89
- if (zodSchemaMetadata) {
90
- for (const zodSchemaProp in zodSchemaMetadata) {
91
- const tmpZodMetadata = zodSchemaMetadata[zodSchemaProp];
92
-
93
- try {
94
- const validation = await tmpZodMetadata.schema.safeParseAsync(arguments[tmpZodMetadata.index]);
95
-
96
- if (!validation.success) {
97
- throw new HttpClientError({
98
- httpCode: 400,
99
- message: `Validation at the [${methodName}] method fails at positional argument [${tmpZodMetadata.index}].`,
100
- data: validation.error.issues
101
- });
102
- }
103
-
104
- arguments[tmpZodMetadata.index] = validation.data;
105
- }
106
- catch (error) {
107
- if (error instanceof HttpClientError) {
108
- throw error;
109
- }
110
-
111
- throw new HttpServerError({
112
- httpCode: 500,
113
- message: `Validation at the [${methodName}] method error at positional argument [${tmpZodMetadata.index}].`,
114
- data: !(error instanceof Error) ? error : [{
115
- message: error.message,
116
- code: error.name,
117
- cause: error.cause
118
- }]
119
- });
120
- }
121
- }
122
- }
123
-
124
- return currentMethod.apply(this, arguments);
125
- }
126
- }
127
- }
128
-
129
- /**
130
- *
131
- * @param path
132
- * @returns
133
- */
134
- export const Get = (
135
- path = "/"
136
- ) => defaultDecorator(path, "Get");
137
-
138
-
139
- /**
140
- *
141
- * @param path
142
- * @returns
143
- */
144
- export const Post = (
145
- path = "/"
146
- ) => defaultDecorator(path, "Post");
147
-
148
-
149
- /**
150
- *
151
- * @param path
152
- * @returns
153
- */
154
- export const Put = (
155
- path = "/"
156
- ) => defaultDecorator(path, "Put");
157
-
158
-
159
- /**
160
- *
161
- * @param path
162
- * @returns
163
- */
164
- export const Patch = (
165
- path = "/"
166
- ) => defaultDecorator(path, "Patch");
167
-
168
-
169
- /**
170
- *
171
- * @param path
172
- * @returns
173
- */
174
- export const Delete = (
175
- path = "/"
176
- ) => defaultDecorator(path, "Delete");
177
-
178
-
179
- /**
180
- *
181
- * @param path
182
- * @returns
183
- */
184
- export const Options = (
185
- path = "/"
186
- ) => defaultDecorator(path, "Options");
187
-
188
- export default {
189
- Get,
190
- Post,
191
- Put,
192
- Patch,
193
- Delete
194
- };
195
-
1
+ export interface IControllerRoute {
2
+ path: string;
3
+ httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
4
+ methodName: string;
5
+ descriptor: PropertyDescriptor;
6
+ }
7
+
8
+ export const controllerRoutesKey = Symbol.for("__bool:controller.routes__");
9
+
10
+ const defaultDecorator =
11
+ (path: string, method: "Get" | "Post" | "Put" | "Patch" | "Delete" | "Options") =>
12
+ (target: Object, methodName: string, descriptor: PropertyDescriptor) => {
13
+ if (!(descriptor.value instanceof Function)) {
14
+ throw Error(`${method} decorator only use for class method.`);
15
+ }
16
+
17
+ // Define controller metadata
18
+ Reflect.defineMetadata(
19
+ controllerRoutesKey,
20
+ [
21
+ ...(Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || []),
22
+ {
23
+ path: !path.startsWith("/") ? `/${path}` : path,
24
+ httpMethod: method.toUpperCase(),
25
+ methodName: methodName,
26
+ descriptor: descriptor
27
+ }
28
+ ],
29
+ target.constructor
30
+ );
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,6 +1,7 @@
1
- export { Controller, controllerKey } from "./controller";
2
- export { Inject, injectKey } from "./inject";
3
- export { Injectable, injectableKey } from "./injectable";
4
- export { Module, moduleKey, type TModuleOptions } from "./module";
5
- export { Get, Post, Put, Patch, Delete, Options, controllerRoutesKey, type IControllerRoute } from "./http";
6
- export { ZodSchema, controllerRouteZodSchemaKey } from "./zodSchema";
1
+ export { Headers, Body, Params, Query, EArgumentTypes } from "./arguments";
2
+ export { Controller, controllerKey } from "./controller";
3
+ export { Inject, injectKey } from "./inject";
4
+ export { Injectable, injectableKey } from "./injectable";
5
+ export { Module, moduleKey, type TModuleOptions } from "./module";
6
+ export { Get, Post, Put, Patch, Delete, Options, controllerRoutesKey, type IControllerRoute } from "./http";
7
+ export { ZodSchema, controllerRouteZodSchemaKey } from "./zodSchema";
@@ -1,19 +1,13 @@
1
- export const injectKey = "design:paramtypes";
2
-
3
- export const Inject = <T extends Object>(
4
- classDefinition: { new(...args: any[]): T }
5
- ) => {
6
- return (
7
- target: Object,
8
- methodName: string | symbol | undefined,
9
- parameterIndex: number
10
- ) => {
11
- const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target) || [];
12
-
13
- designParameterTypes[parameterIndex] = classDefinition;
14
-
15
- Reflect.defineMetadata(injectKey, designParameterTypes, target);
16
- }
17
- }
18
-
19
- 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,12 +1,11 @@
1
- export const injectableKey = "__bool:injectable__";
2
-
3
- export const Injectable = () => <T extends Object>(
4
- target: T,
5
- context?: ClassDecoratorContext
6
- ) => {
7
- Reflect.defineMetadata(injectableKey, undefined, target);
8
-
9
- return target;
10
- }
11
-
12
- 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
+ return target;
9
+ };
10
+
11
+ export default Injectable;
@@ -1,22 +1,21 @@
1
- export type TModuleOptions = Partial<{
2
- prefix: string;
3
- controllers: Array<new (...args: any[]) => unknown>;
4
- dependencies: Array<new (...args: any[]) => unknown>;
5
- allowOrigins: string | Array<string>;
6
- allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
7
- }> | undefined;
8
-
9
- export const moduleKey = "__bool:module__";
10
-
11
- export const Module = (
12
- args?: TModuleOptions
13
- ) => <T extends { new(...args: any[]): {} }>(
14
- target: T,
15
- context?: ClassDecoratorContext
16
- ) => {
17
- Reflect.defineMetadata(moduleKey, args, target);
18
-
19
- return target;
20
- }
21
-
22
- export default Module;
1
+ export type TModuleOptions =
2
+ | Partial<{
3
+ prefix: string;
4
+ controllers: Array<new (...args: any[]) => unknown>;
5
+ dependencies: Array<new (...args: any[]) => unknown>;
6
+ allowOrigins: string | Array<string>;
7
+ allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
8
+ }>
9
+ | undefined;
10
+
11
+ export const moduleKey = Symbol.for("__bool:module__");
12
+
13
+ export const Module =
14
+ (args?: TModuleOptions) =>
15
+ <T extends { new (...args: any[]): {} }>(target: T) => {
16
+ Reflect.defineMetadata(moduleKey, args, target);
17
+
18
+ return target;
19
+ };
20
+
21
+ export default Module;