@bool-ts/core 1.5.6 → 1.5.8
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 -9
- package/__test/beforeDispatcher.ts +9 -9
- package/__test/controller.ts +68 -68
- package/__test/firstGuard.ts +10 -10
- package/__test/firstMiddleware.ts +9 -9
- package/__test/index.ts +8 -8
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +22 -22
- package/__test/repository.ts +16 -16
- package/__test/secondGuard.ts +10 -10
- package/__test/secondMiddleware.ts +9 -9
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/entities/route.js +0 -1
- package/dist/hooks/factory.js +1 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -3
- package/jsconfig.json +27 -0
- package/package.json +31 -31
- package/src/decorators/arguments.ts +214 -214
- package/src/decorators/controller.ts +22 -22
- package/src/decorators/dispatcher.ts +19 -19
- package/src/decorators/guard.ts +19 -19
- package/src/decorators/http.ts +81 -81
- package/src/decorators/index.ts +28 -28
- package/src/decorators/inject.ts +13 -13
- package/src/decorators/injectable.ts +8 -8
- package/src/decorators/middleware.ts +19 -19
- package/src/decorators/module.ts +92 -92
- package/src/decorators/zodSchema.ts +20 -20
- package/src/entities/index.ts +3 -3
- package/src/entities/route.ts +327 -328
- package/src/entities/router.ts +35 -35
- package/src/entities/routerGroup.ts +34 -34
- package/src/hooks/factory.ts +616 -616
- 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 +61 -63
- package/src/http/serverError.ts +38 -38
- package/src/index.ts +6 -6
- package/src/interfaces/controller.ts +1 -1
- package/src/interfaces/dispatcher.ts +3 -3
- package/src/interfaces/guard.ts +3 -3
- package/src/interfaces/index.ts +5 -5
- package/src/interfaces/middleware.ts +3 -3
- package/src/interfaces/module.ts +1 -1
- package/test.http +31 -31
- package/tsconfig.json +108 -107
|
@@ -1,214 +1,214 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
|
-
|
|
3
|
-
export enum EArgumentTypes {
|
|
4
|
-
requestHeaders = "REQUEST_HEADERS",
|
|
5
|
-
body = "BODY",
|
|
6
|
-
params = "PARAMS",
|
|
7
|
-
param = "PARAM",
|
|
8
|
-
query = "QUERY",
|
|
9
|
-
request = "REQUEST",
|
|
10
|
-
responseHeaders = "RESPONSE_HEADERS"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type TArgumentsMetadata =
|
|
14
|
-
| {
|
|
15
|
-
index: number;
|
|
16
|
-
type: EArgumentTypes.requestHeaders;
|
|
17
|
-
zodSchema?: Zod.Schema;
|
|
18
|
-
}
|
|
19
|
-
| {
|
|
20
|
-
index: number;
|
|
21
|
-
type: EArgumentTypes.body;
|
|
22
|
-
zodSchema?: Zod.Schema;
|
|
23
|
-
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
index: number;
|
|
27
|
-
type: EArgumentTypes.params;
|
|
28
|
-
zodSchema?: Zod.Schema;
|
|
29
|
-
}
|
|
30
|
-
| {
|
|
31
|
-
index: number;
|
|
32
|
-
type: EArgumentTypes.param;
|
|
33
|
-
key: string;
|
|
34
|
-
zodSchema?: Zod.Schema;
|
|
35
|
-
}
|
|
36
|
-
| {
|
|
37
|
-
index: number;
|
|
38
|
-
type: EArgumentTypes.query;
|
|
39
|
-
zodSchema?: Zod.Schema;
|
|
40
|
-
}
|
|
41
|
-
| {
|
|
42
|
-
index: number;
|
|
43
|
-
type: EArgumentTypes.request;
|
|
44
|
-
zodSchema?: Zod.Schema;
|
|
45
|
-
}
|
|
46
|
-
| {
|
|
47
|
-
index: number;
|
|
48
|
-
type: EArgumentTypes.responseHeaders;
|
|
49
|
-
zodSchema?: Zod.Schema;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const argumentsKey = Symbol.for("__bool:arguments__");
|
|
53
|
-
|
|
54
|
-
export const RequestHeaders = (zodSchema?: Zod.Schema) => {
|
|
55
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
56
|
-
if (!methodName) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const headersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
61
|
-
|
|
62
|
-
headersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
63
|
-
index: parameterIndex,
|
|
64
|
-
type: EArgumentTypes.requestHeaders,
|
|
65
|
-
zodSchema: zodSchema
|
|
66
|
-
} satisfies Extract<
|
|
67
|
-
TArgumentsMetadata,
|
|
68
|
-
{
|
|
69
|
-
type: EArgumentTypes.requestHeaders;
|
|
70
|
-
}
|
|
71
|
-
>;
|
|
72
|
-
|
|
73
|
-
Reflect.defineMetadata(argumentsKey, headersMetadata, target.constructor, methodName);
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const Body = (zodSchema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") => {
|
|
78
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
79
|
-
if (!methodName) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
84
|
-
|
|
85
|
-
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
86
|
-
index: parameterIndex,
|
|
87
|
-
type: EArgumentTypes.body,
|
|
88
|
-
zodSchema: zodSchema,
|
|
89
|
-
parser: parser
|
|
90
|
-
} satisfies Extract<
|
|
91
|
-
TArgumentsMetadata,
|
|
92
|
-
{
|
|
93
|
-
type: EArgumentTypes.body;
|
|
94
|
-
}
|
|
95
|
-
>;
|
|
96
|
-
|
|
97
|
-
Reflect.defineMetadata(argumentsKey, bodyMetadata, target.constructor, methodName);
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const Params =
|
|
102
|
-
(zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
103
|
-
if (!methodName) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
108
|
-
|
|
109
|
-
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
110
|
-
index: parameterIndex,
|
|
111
|
-
type: EArgumentTypes.params,
|
|
112
|
-
zodSchema: zodSchema
|
|
113
|
-
} satisfies Extract<
|
|
114
|
-
TArgumentsMetadata,
|
|
115
|
-
{
|
|
116
|
-
type: EArgumentTypes.params;
|
|
117
|
-
}
|
|
118
|
-
>;
|
|
119
|
-
|
|
120
|
-
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export const Param = (key: string, zodSchema?: Zod.Schema) => {
|
|
124
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
125
|
-
if (!methodName) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
130
|
-
|
|
131
|
-
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
132
|
-
index: parameterIndex,
|
|
133
|
-
type: EArgumentTypes.param,
|
|
134
|
-
key: key,
|
|
135
|
-
zodSchema: zodSchema
|
|
136
|
-
} satisfies Extract<
|
|
137
|
-
TArgumentsMetadata,
|
|
138
|
-
{
|
|
139
|
-
type: EArgumentTypes.param;
|
|
140
|
-
}
|
|
141
|
-
>;
|
|
142
|
-
|
|
143
|
-
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const Query = (zodSchema?: Zod.Schema) => {
|
|
148
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
149
|
-
if (!methodName) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
154
|
-
|
|
155
|
-
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
156
|
-
index: parameterIndex,
|
|
157
|
-
type: EArgumentTypes.query,
|
|
158
|
-
zodSchema: zodSchema
|
|
159
|
-
} satisfies Extract<
|
|
160
|
-
TArgumentsMetadata,
|
|
161
|
-
{
|
|
162
|
-
type: EArgumentTypes.query;
|
|
163
|
-
}
|
|
164
|
-
>;
|
|
165
|
-
|
|
166
|
-
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
167
|
-
};
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export const Request = (zodSchema?: Zod.Schema) => {
|
|
171
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
172
|
-
if (!methodName) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
177
|
-
|
|
178
|
-
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
179
|
-
index: parameterIndex,
|
|
180
|
-
type: EArgumentTypes.request,
|
|
181
|
-
zodSchema: zodSchema
|
|
182
|
-
} satisfies Extract<
|
|
183
|
-
TArgumentsMetadata,
|
|
184
|
-
{
|
|
185
|
-
type: EArgumentTypes.request;
|
|
186
|
-
}
|
|
187
|
-
>;
|
|
188
|
-
|
|
189
|
-
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export const ResponseHeaders = (zodSchema?: Zod.Schema) => {
|
|
194
|
-
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
195
|
-
if (!methodName) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
200
|
-
|
|
201
|
-
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
202
|
-
index: parameterIndex,
|
|
203
|
-
type: EArgumentTypes.responseHeaders,
|
|
204
|
-
zodSchema: zodSchema
|
|
205
|
-
} satisfies Extract<
|
|
206
|
-
TArgumentsMetadata,
|
|
207
|
-
{
|
|
208
|
-
type: EArgumentTypes.responseHeaders;
|
|
209
|
-
}
|
|
210
|
-
>;
|
|
211
|
-
|
|
212
|
-
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
213
|
-
};
|
|
214
|
-
};
|
|
1
|
+
import * as Zod from "zod";
|
|
2
|
+
|
|
3
|
+
export enum EArgumentTypes {
|
|
4
|
+
requestHeaders = "REQUEST_HEADERS",
|
|
5
|
+
body = "BODY",
|
|
6
|
+
params = "PARAMS",
|
|
7
|
+
param = "PARAM",
|
|
8
|
+
query = "QUERY",
|
|
9
|
+
request = "REQUEST",
|
|
10
|
+
responseHeaders = "RESPONSE_HEADERS"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TArgumentsMetadata =
|
|
14
|
+
| {
|
|
15
|
+
index: number;
|
|
16
|
+
type: EArgumentTypes.requestHeaders;
|
|
17
|
+
zodSchema?: Zod.Schema;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
index: number;
|
|
21
|
+
type: EArgumentTypes.body;
|
|
22
|
+
zodSchema?: Zod.Schema;
|
|
23
|
+
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
index: number;
|
|
27
|
+
type: EArgumentTypes.params;
|
|
28
|
+
zodSchema?: Zod.Schema;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
index: number;
|
|
32
|
+
type: EArgumentTypes.param;
|
|
33
|
+
key: string;
|
|
34
|
+
zodSchema?: Zod.Schema;
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
index: number;
|
|
38
|
+
type: EArgumentTypes.query;
|
|
39
|
+
zodSchema?: Zod.Schema;
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
index: number;
|
|
43
|
+
type: EArgumentTypes.request;
|
|
44
|
+
zodSchema?: Zod.Schema;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
index: number;
|
|
48
|
+
type: EArgumentTypes.responseHeaders;
|
|
49
|
+
zodSchema?: Zod.Schema;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const argumentsKey = Symbol.for("__bool:arguments__");
|
|
53
|
+
|
|
54
|
+
export const RequestHeaders = (zodSchema?: Zod.Schema) => {
|
|
55
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
56
|
+
if (!methodName) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const headersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
61
|
+
|
|
62
|
+
headersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
63
|
+
index: parameterIndex,
|
|
64
|
+
type: EArgumentTypes.requestHeaders,
|
|
65
|
+
zodSchema: zodSchema
|
|
66
|
+
} satisfies Extract<
|
|
67
|
+
TArgumentsMetadata,
|
|
68
|
+
{
|
|
69
|
+
type: EArgumentTypes.requestHeaders;
|
|
70
|
+
}
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
Reflect.defineMetadata(argumentsKey, headersMetadata, target.constructor, methodName);
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const Body = (zodSchema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") => {
|
|
78
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
79
|
+
if (!methodName) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
84
|
+
|
|
85
|
+
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
86
|
+
index: parameterIndex,
|
|
87
|
+
type: EArgumentTypes.body,
|
|
88
|
+
zodSchema: zodSchema,
|
|
89
|
+
parser: parser
|
|
90
|
+
} satisfies Extract<
|
|
91
|
+
TArgumentsMetadata,
|
|
92
|
+
{
|
|
93
|
+
type: EArgumentTypes.body;
|
|
94
|
+
}
|
|
95
|
+
>;
|
|
96
|
+
|
|
97
|
+
Reflect.defineMetadata(argumentsKey, bodyMetadata, target.constructor, methodName);
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const Params =
|
|
102
|
+
(zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
103
|
+
if (!methodName) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
108
|
+
|
|
109
|
+
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
110
|
+
index: parameterIndex,
|
|
111
|
+
type: EArgumentTypes.params,
|
|
112
|
+
zodSchema: zodSchema
|
|
113
|
+
} satisfies Extract<
|
|
114
|
+
TArgumentsMetadata,
|
|
115
|
+
{
|
|
116
|
+
type: EArgumentTypes.params;
|
|
117
|
+
}
|
|
118
|
+
>;
|
|
119
|
+
|
|
120
|
+
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const Param = (key: string, zodSchema?: Zod.Schema) => {
|
|
124
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
125
|
+
if (!methodName) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
130
|
+
|
|
131
|
+
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
132
|
+
index: parameterIndex,
|
|
133
|
+
type: EArgumentTypes.param,
|
|
134
|
+
key: key,
|
|
135
|
+
zodSchema: zodSchema
|
|
136
|
+
} satisfies Extract<
|
|
137
|
+
TArgumentsMetadata,
|
|
138
|
+
{
|
|
139
|
+
type: EArgumentTypes.param;
|
|
140
|
+
}
|
|
141
|
+
>;
|
|
142
|
+
|
|
143
|
+
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const Query = (zodSchema?: Zod.Schema) => {
|
|
148
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
149
|
+
if (!methodName) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
154
|
+
|
|
155
|
+
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
156
|
+
index: parameterIndex,
|
|
157
|
+
type: EArgumentTypes.query,
|
|
158
|
+
zodSchema: zodSchema
|
|
159
|
+
} satisfies Extract<
|
|
160
|
+
TArgumentsMetadata,
|
|
161
|
+
{
|
|
162
|
+
type: EArgumentTypes.query;
|
|
163
|
+
}
|
|
164
|
+
>;
|
|
165
|
+
|
|
166
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const Request = (zodSchema?: Zod.Schema) => {
|
|
171
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
172
|
+
if (!methodName) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
177
|
+
|
|
178
|
+
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
179
|
+
index: parameterIndex,
|
|
180
|
+
type: EArgumentTypes.request,
|
|
181
|
+
zodSchema: zodSchema
|
|
182
|
+
} satisfies Extract<
|
|
183
|
+
TArgumentsMetadata,
|
|
184
|
+
{
|
|
185
|
+
type: EArgumentTypes.request;
|
|
186
|
+
}
|
|
187
|
+
>;
|
|
188
|
+
|
|
189
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const ResponseHeaders = (zodSchema?: Zod.Schema) => {
|
|
194
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
195
|
+
if (!methodName) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
200
|
+
|
|
201
|
+
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
202
|
+
index: parameterIndex,
|
|
203
|
+
type: EArgumentTypes.responseHeaders,
|
|
204
|
+
zodSchema: zodSchema
|
|
205
|
+
} satisfies Extract<
|
|
206
|
+
TArgumentsMetadata,
|
|
207
|
+
{
|
|
208
|
+
type: EArgumentTypes.responseHeaders;
|
|
209
|
+
}
|
|
210
|
+
>;
|
|
211
|
+
|
|
212
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
213
|
+
};
|
|
214
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { IController } from "../interfaces/controller";
|
|
2
|
-
import { controllerHttpKey, type THttpMetadata } from "./http";
|
|
3
|
-
|
|
4
|
-
export type TControllerMetadata = Required<{
|
|
5
|
-
prefix: string;
|
|
6
|
-
httpMetadata: THttpMetadata;
|
|
7
|
-
}>;
|
|
8
|
-
|
|
9
|
-
export const controllerKey = Symbol.for("__bool:controller__");
|
|
10
|
-
|
|
11
|
-
export const Controller =
|
|
12
|
-
(prefix: string) =>
|
|
13
|
-
<T extends { new (...args: any[]): IController }>(target: T) => {
|
|
14
|
-
const metadata: TControllerMetadata = {
|
|
15
|
-
prefix: !prefix.startsWith("/") ? `/${prefix}` : prefix,
|
|
16
|
-
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || [])]
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
Reflect.defineMetadata(controllerKey, metadata, target);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default Controller;
|
|
1
|
+
import type { IController } from "../interfaces/controller";
|
|
2
|
+
import { controllerHttpKey, type THttpMetadata } from "./http";
|
|
3
|
+
|
|
4
|
+
export type TControllerMetadata = Required<{
|
|
5
|
+
prefix: string;
|
|
6
|
+
httpMetadata: THttpMetadata;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
export const controllerKey = Symbol.for("__bool:controller__");
|
|
10
|
+
|
|
11
|
+
export const Controller =
|
|
12
|
+
(prefix: string) =>
|
|
13
|
+
<T extends { new (...args: any[]): IController }>(target: T) => {
|
|
14
|
+
const metadata: TControllerMetadata = {
|
|
15
|
+
prefix: !prefix.startsWith("/") ? `/${prefix}` : prefix,
|
|
16
|
+
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || [])]
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Reflect.defineMetadata(controllerKey, metadata, target);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default Controller;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { IDispatcher } from "../interfaces/dispatcher";
|
|
2
|
-
|
|
3
|
-
export type TDispatcherMetadata = undefined;
|
|
4
|
-
|
|
5
|
-
export const dispatcherKey = Symbol.for("__bool:dispatcher__");
|
|
6
|
-
|
|
7
|
-
export const Dispatcher =
|
|
8
|
-
() =>
|
|
9
|
-
<T extends { new (...args: any[]): IDispatcher }>(target: T) => {
|
|
10
|
-
if (!("execute" in target.prototype) || typeof target.prototype.execute !== "function") {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const metadata: TDispatcherMetadata = undefined;
|
|
15
|
-
|
|
16
|
-
Reflect.defineMetadata(dispatcherKey, metadata, target);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default Dispatcher;
|
|
1
|
+
import type { IDispatcher } from "../interfaces/dispatcher";
|
|
2
|
+
|
|
3
|
+
export type TDispatcherMetadata = undefined;
|
|
4
|
+
|
|
5
|
+
export const dispatcherKey = Symbol.for("__bool:dispatcher__");
|
|
6
|
+
|
|
7
|
+
export const Dispatcher =
|
|
8
|
+
() =>
|
|
9
|
+
<T extends { new (...args: any[]): IDispatcher }>(target: T) => {
|
|
10
|
+
if (!("execute" in target.prototype) || typeof target.prototype.execute !== "function") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const metadata: TDispatcherMetadata = undefined;
|
|
15
|
+
|
|
16
|
+
Reflect.defineMetadata(dispatcherKey, metadata, target);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default Dispatcher;
|
package/src/decorators/guard.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { IGuard } from "../interfaces";
|
|
2
|
-
|
|
3
|
-
export type TGuardMetadata = undefined;
|
|
4
|
-
|
|
5
|
-
export const guardKey = Symbol.for("__bool:guard__");
|
|
6
|
-
|
|
7
|
-
export const Guard =
|
|
8
|
-
() =>
|
|
9
|
-
<T extends { new (...args: any[]): IGuard }>(target: T) => {
|
|
10
|
-
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const metadata = undefined;
|
|
15
|
-
|
|
16
|
-
Reflect.defineMetadata(guardKey, metadata, target);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default Guard;
|
|
1
|
+
import type { IGuard } from "../interfaces";
|
|
2
|
+
|
|
3
|
+
export type TGuardMetadata = undefined;
|
|
4
|
+
|
|
5
|
+
export const guardKey = Symbol.for("__bool:guard__");
|
|
6
|
+
|
|
7
|
+
export const Guard =
|
|
8
|
+
() =>
|
|
9
|
+
<T extends { new (...args: any[]): IGuard }>(target: T) => {
|
|
10
|
+
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const metadata = undefined;
|
|
15
|
+
|
|
16
|
+
Reflect.defineMetadata(guardKey, metadata, target);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default Guard;
|