@bool-ts/core 1.1.0 → 1.1.1

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.
@@ -1,185 +1,185 @@
1
- export interface IControllerRoute {
2
- path: string;
3
- httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
4
- methodName: string;
5
- descriptor: PropertyDescriptor;
6
- }
7
-
8
-
9
- export const controllerRoutesKey = "__bool:controller.routes__";
10
-
11
- /**
12
- *
13
- * @param path
14
- * @returns
15
- */
16
- export const Get = (
17
- path = "/"
18
- ) => (
19
- target: Object,
20
- methodName: string,
21
- descriptor: PropertyDescriptor
22
- ) => {
23
- if (typeof descriptor.value !== "function") {
24
- throw Error("Get decorator only use for method.");
25
- }
26
-
27
- Reflect.defineMetadata(controllerRoutesKey, [
28
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
29
- {
30
- path: !path.startsWith("/") ? `/${path}` : path,
31
- httpMethod: "GET",
32
- methodName: methodName,
33
- descriptor: descriptor
34
- }
35
- ], target.constructor);
36
- }
37
-
38
-
39
- /**
40
- *
41
- * @param path
42
- * @returns
43
- */
44
- export const Post = (
45
- path = "/"
46
- ) => (
47
- target: Object,
48
- methodName: string,
49
- descriptor: PropertyDescriptor
50
- ) => {
51
- if (typeof descriptor.value !== "function") {
52
- throw Error("Post decorator only use for method.");
53
- }
54
-
55
- Reflect.defineMetadata(controllerRoutesKey, [
56
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
57
- {
58
- path: !path.startsWith("/") ? `/${path}` : path,
59
- httpMethod: "POST",
60
- methodName: methodName,
61
- descriptor: descriptor
62
- }
63
- ], target.constructor);
64
- }
65
-
66
-
67
- /**
68
- *
69
- * @param path
70
- * @returns
71
- */
72
- export const Put = (
73
- path = "/"
74
- ) => (
75
- target: Object,
76
- methodName: string,
77
- descriptor: PropertyDescriptor
78
- ) => {
79
- if (typeof descriptor.value !== "function") {
80
- throw Error("Put decorator only use for method.");
81
- }
82
-
83
- Reflect.defineMetadata(controllerRoutesKey, [
84
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
85
- {
86
- path: !path.startsWith("/") ? `/${path}` : path,
87
- httpMethod: "PUT",
88
- methodName: methodName,
89
- descriptor: descriptor
90
- }
91
- ], target.constructor);
92
- }
93
-
94
-
95
- /**
96
- *
97
- * @param path
98
- * @returns
99
- */
100
- export const Patch = (
101
- path = "/"
102
- ) => (
103
- target: Object,
104
- methodName: string,
105
- descriptor: PropertyDescriptor
106
- ) => {
107
- if (typeof descriptor.value !== "function") {
108
- throw Error("Patch decorator only use for method.");
109
- }
110
-
111
- Reflect.defineMetadata(controllerRoutesKey, [
112
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
113
- {
114
- path: !path.startsWith("/") ? `/${path}` : path,
115
- httpMethod: "PATCH",
116
- methodName: methodName,
117
- descriptor: descriptor
118
- }
119
- ], target.constructor);
120
- }
121
-
122
-
123
- /**
124
- *
125
- * @param path
126
- * @returns
127
- */
128
- export const Delete = (
129
- path = "/"
130
- ) => (
131
- target: Object,
132
- methodName: string,
133
- descriptor: PropertyDescriptor
134
- ) => {
135
- if (typeof descriptor.value !== "function") {
136
- throw Error("Delete decorator only use for method.");
137
- }
138
-
139
- Reflect.defineMetadata(controllerRoutesKey, [
140
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
141
- {
142
- path: !path.startsWith("/") ? `/${path}` : path,
143
- httpMethod: "DELETE",
144
- methodName: methodName,
145
- descriptor: descriptor
146
- }
147
- ], target.constructor);
148
- }
149
-
150
-
151
- /**
152
- *
153
- * @param path
154
- * @returns
155
- */
156
- export const Options = (
157
- path = "/"
158
- ) => (
159
- target: Object,
160
- methodName: string,
161
- descriptor: PropertyDescriptor
162
- ) => {
163
- if (typeof descriptor.value !== "function") {
164
- throw Error("Options decorator only use for method.");
165
- }
166
-
167
- Reflect.defineMetadata(controllerRoutesKey, [
168
- ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
169
- {
170
- path: !path.startsWith("/") ? `/${path}` : path,
171
- httpMethod: "OPTIONS",
172
- methodName: methodName,
173
- descriptor: descriptor
174
- }
175
- ], target.constructor);
176
- }
177
-
178
- export default {
179
- Get,
180
- Post,
181
- Put,
182
- Patch,
183
- Delete
184
- };
185
-
1
+ export interface IControllerRoute {
2
+ path: string;
3
+ httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
4
+ methodName: string;
5
+ descriptor: PropertyDescriptor;
6
+ }
7
+
8
+
9
+ export const controllerRoutesKey = "__bool:controller.routes__";
10
+
11
+ /**
12
+ *
13
+ * @param path
14
+ * @returns
15
+ */
16
+ export const Get = (
17
+ path = "/"
18
+ ) => (
19
+ target: Object,
20
+ methodName: string,
21
+ descriptor: PropertyDescriptor
22
+ ) => {
23
+ if (typeof descriptor.value !== "function") {
24
+ throw Error("Get decorator only use for method.");
25
+ }
26
+
27
+ Reflect.defineMetadata(controllerRoutesKey, [
28
+ ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
29
+ {
30
+ path: !path.startsWith("/") ? `/${path}` : path,
31
+ httpMethod: "GET",
32
+ methodName: methodName,
33
+ descriptor: descriptor
34
+ }
35
+ ], target.constructor);
36
+ }
37
+
38
+
39
+ /**
40
+ *
41
+ * @param path
42
+ * @returns
43
+ */
44
+ export const Post = (
45
+ path = "/"
46
+ ) => (
47
+ target: Object,
48
+ methodName: string,
49
+ descriptor: PropertyDescriptor
50
+ ) => {
51
+ if (typeof descriptor.value !== "function") {
52
+ throw Error("Post decorator only use for method.");
53
+ }
54
+
55
+ Reflect.defineMetadata(controllerRoutesKey, [
56
+ ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
57
+ {
58
+ path: !path.startsWith("/") ? `/${path}` : path,
59
+ httpMethod: "POST",
60
+ methodName: methodName,
61
+ descriptor: descriptor
62
+ }
63
+ ], target.constructor);
64
+ }
65
+
66
+
67
+ /**
68
+ *
69
+ * @param path
70
+ * @returns
71
+ */
72
+ export const Put = (
73
+ path = "/"
74
+ ) => (
75
+ target: Object,
76
+ methodName: string,
77
+ descriptor: PropertyDescriptor
78
+ ) => {
79
+ if (typeof descriptor.value !== "function") {
80
+ throw Error("Put decorator only use for method.");
81
+ }
82
+
83
+ Reflect.defineMetadata(controllerRoutesKey, [
84
+ ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
85
+ {
86
+ path: !path.startsWith("/") ? `/${path}` : path,
87
+ httpMethod: "PUT",
88
+ methodName: methodName,
89
+ descriptor: descriptor
90
+ }
91
+ ], target.constructor);
92
+ }
93
+
94
+
95
+ /**
96
+ *
97
+ * @param path
98
+ * @returns
99
+ */
100
+ export const Patch = (
101
+ path = "/"
102
+ ) => (
103
+ target: Object,
104
+ methodName: string,
105
+ descriptor: PropertyDescriptor
106
+ ) => {
107
+ if (typeof descriptor.value !== "function") {
108
+ throw Error("Patch decorator only use for method.");
109
+ }
110
+
111
+ Reflect.defineMetadata(controllerRoutesKey, [
112
+ ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
113
+ {
114
+ path: !path.startsWith("/") ? `/${path}` : path,
115
+ httpMethod: "PATCH",
116
+ methodName: methodName,
117
+ descriptor: descriptor
118
+ }
119
+ ], target.constructor);
120
+ }
121
+
122
+
123
+ /**
124
+ *
125
+ * @param path
126
+ * @returns
127
+ */
128
+ export const Delete = (
129
+ path = "/"
130
+ ) => (
131
+ target: Object,
132
+ methodName: string,
133
+ descriptor: PropertyDescriptor
134
+ ) => {
135
+ if (typeof descriptor.value !== "function") {
136
+ throw Error("Delete decorator only use for method.");
137
+ }
138
+
139
+ Reflect.defineMetadata(controllerRoutesKey, [
140
+ ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
141
+ {
142
+ path: !path.startsWith("/") ? `/${path}` : path,
143
+ httpMethod: "DELETE",
144
+ methodName: methodName,
145
+ descriptor: descriptor
146
+ }
147
+ ], target.constructor);
148
+ }
149
+
150
+
151
+ /**
152
+ *
153
+ * @param path
154
+ * @returns
155
+ */
156
+ export const Options = (
157
+ path = "/"
158
+ ) => (
159
+ target: Object,
160
+ methodName: string,
161
+ descriptor: PropertyDescriptor
162
+ ) => {
163
+ if (typeof descriptor.value !== "function") {
164
+ throw Error("Options decorator only use for method.");
165
+ }
166
+
167
+ Reflect.defineMetadata(controllerRoutesKey, [
168
+ ...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
169
+ {
170
+ path: !path.startsWith("/") ? `/${path}` : path,
171
+ httpMethod: "OPTIONS",
172
+ methodName: methodName,
173
+ descriptor: descriptor
174
+ }
175
+ ], target.constructor);
176
+ }
177
+
178
+ export default {
179
+ Get,
180
+ Post,
181
+ Put,
182
+ Patch,
183
+ Delete
184
+ };
185
+
@@ -1,5 +1,5 @@
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";
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";
@@ -1,19 +1,19 @@
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
- parameterName: 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>(
4
+ classDefinition: { new(...args: any[]): T }
5
+ ) => {
6
+ return (
7
+ target: Object,
8
+ parameterName: 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,12 +1,12 @@
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 = "__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,21 +1,21 @@
1
- export type TModuleOptions = Partial<{
2
- controllers: Array<new (...args: any[]) => unknown>;
3
- dependencies: Array<new (...args: any[]) => unknown>;
4
- allowOrigins: string | Array<string>;
5
- allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
6
- }> | undefined;
7
-
8
- export const moduleKey = "__bool:module__";
9
-
10
- export const Module = (
11
- args?: TModuleOptions
12
- ) => <T extends { new(...args: any[]): {} }>(
13
- target: T,
14
- context?: ClassDecoratorContext
15
- ) => {
16
- Reflect.defineMetadata(moduleKey, args, target);
17
-
18
- return target;
19
- }
20
-
21
- export default Module;
1
+ export type TModuleOptions = Partial<{
2
+ controllers: Array<new (...args: any[]) => unknown>;
3
+ dependencies: Array<new (...args: any[]) => unknown>;
4
+ allowOrigins: string | Array<string>;
5
+ allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
6
+ }> | undefined;
7
+
8
+ export const moduleKey = "__bool:module__";
9
+
10
+ export const Module = (
11
+ args?: TModuleOptions
12
+ ) => <T extends { new(...args: any[]): {} }>(
13
+ target: T,
14
+ context?: ClassDecoratorContext
15
+ ) => {
16
+ Reflect.defineMetadata(moduleKey, args, target);
17
+
18
+ return target;
19
+ }
20
+
21
+ export default Module;