@bool-ts/core 1.6.14 → 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 +496 -404
- 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 -809
- 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
|
@@ -1,286 +1,286 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
|
-
import {
|
|
3
|
-
argumentsKey,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
requestHeaderArgsKey,
|
|
11
|
-
requestHeadersArgsKey,
|
|
12
|
-
responseHeadersArgsKey,
|
|
13
|
-
routeModelArgsKey
|
|
14
|
-
} from "../keys";
|
|
15
|
-
|
|
16
|
-
export type TArgumentsMetadata =
|
|
17
|
-
| {
|
|
18
|
-
index: number;
|
|
19
|
-
type: typeof requestHeadersArgsKey;
|
|
20
|
-
zodSchema?: Zod.Schema;
|
|
21
|
-
}
|
|
22
|
-
| {
|
|
23
|
-
index: number;
|
|
24
|
-
type: typeof requestHeaderArgsKey;
|
|
25
|
-
key: string;
|
|
26
|
-
zodSchema?: Zod.Schema;
|
|
27
|
-
}
|
|
28
|
-
| {
|
|
29
|
-
index: number;
|
|
30
|
-
type: typeof
|
|
31
|
-
zodSchema?: Zod.Schema;
|
|
32
|
-
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
33
|
-
}
|
|
34
|
-
| {
|
|
35
|
-
index: number;
|
|
36
|
-
type: typeof paramsArgsKey;
|
|
37
|
-
zodSchema?: Zod.Schema;
|
|
38
|
-
}
|
|
39
|
-
| {
|
|
40
|
-
index: number;
|
|
41
|
-
type: typeof paramArgsKey;
|
|
42
|
-
key: string;
|
|
43
|
-
zodSchema?: Zod.Schema;
|
|
44
|
-
}
|
|
45
|
-
| {
|
|
46
|
-
index: number;
|
|
47
|
-
type: typeof queryArgsKey;
|
|
48
|
-
zodSchema?: Zod.Schema;
|
|
49
|
-
}
|
|
50
|
-
| {
|
|
51
|
-
index: number;
|
|
52
|
-
type: typeof requestArgsKey;
|
|
53
|
-
zodSchema?: Zod.Schema;
|
|
54
|
-
}
|
|
55
|
-
| {
|
|
56
|
-
index: number;
|
|
57
|
-
type: typeof responseHeadersArgsKey;
|
|
58
|
-
}
|
|
59
|
-
| {
|
|
60
|
-
index: number;
|
|
61
|
-
type: typeof contextArgsKey;
|
|
62
|
-
key?: symbol;
|
|
63
|
-
}
|
|
64
|
-
| {
|
|
65
|
-
index: number;
|
|
66
|
-
type: typeof routeModelArgsKey;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const RequestHeaders =
|
|
70
|
-
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
71
|
-
if (!methodName) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const requestHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
76
|
-
|
|
77
|
-
requestHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
78
|
-
index: parameterIndex,
|
|
79
|
-
type: requestHeadersArgsKey,
|
|
80
|
-
zodSchema: schema
|
|
81
|
-
} satisfies Extract<
|
|
82
|
-
TArgumentsMetadata,
|
|
83
|
-
{
|
|
84
|
-
type: typeof requestHeadersArgsKey;
|
|
85
|
-
}
|
|
86
|
-
>;
|
|
87
|
-
|
|
88
|
-
Reflect.defineMetadata(argumentsKey, requestHeadersMetadata, target.constructor, methodName);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const RequestHeader =
|
|
92
|
-
(key: string, schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
93
|
-
if (!methodName) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const requestHeaderMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
98
|
-
|
|
99
|
-
requestHeaderMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
100
|
-
index: parameterIndex,
|
|
101
|
-
type: requestHeaderArgsKey,
|
|
102
|
-
key: key,
|
|
103
|
-
zodSchema: schema
|
|
104
|
-
} satisfies Extract<
|
|
105
|
-
TArgumentsMetadata,
|
|
106
|
-
{
|
|
107
|
-
type: typeof requestHeaderArgsKey;
|
|
108
|
-
}
|
|
109
|
-
>;
|
|
110
|
-
|
|
111
|
-
Reflect.defineMetadata(argumentsKey, requestHeaderMetadata, target.constructor, methodName);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export const
|
|
115
|
-
(schema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") =>
|
|
116
|
-
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
117
|
-
if (!methodName) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
122
|
-
|
|
123
|
-
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
124
|
-
index: parameterIndex,
|
|
125
|
-
type:
|
|
126
|
-
zodSchema: schema,
|
|
127
|
-
parser: parser
|
|
128
|
-
} satisfies Extract<
|
|
129
|
-
TArgumentsMetadata,
|
|
130
|
-
{
|
|
131
|
-
type: typeof
|
|
132
|
-
}
|
|
133
|
-
>;
|
|
134
|
-
|
|
135
|
-
Reflect.defineMetadata(argumentsKey, bodyMetadata, target.constructor, methodName);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const Params =
|
|
139
|
-
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
140
|
-
if (!methodName) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
145
|
-
|
|
146
|
-
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
147
|
-
index: parameterIndex,
|
|
148
|
-
type: paramsArgsKey,
|
|
149
|
-
zodSchema: schema
|
|
150
|
-
} satisfies Extract<
|
|
151
|
-
TArgumentsMetadata,
|
|
152
|
-
{
|
|
153
|
-
type: typeof paramsArgsKey;
|
|
154
|
-
}
|
|
155
|
-
>;
|
|
156
|
-
|
|
157
|
-
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export const Param =
|
|
161
|
-
(key: string, schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
162
|
-
if (!methodName) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const paramMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
167
|
-
|
|
168
|
-
paramMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
169
|
-
index: parameterIndex,
|
|
170
|
-
type: paramArgsKey,
|
|
171
|
-
key: key,
|
|
172
|
-
zodSchema: schema
|
|
173
|
-
} satisfies Extract<
|
|
174
|
-
TArgumentsMetadata,
|
|
175
|
-
{
|
|
176
|
-
type: typeof paramArgsKey;
|
|
177
|
-
}
|
|
178
|
-
>;
|
|
179
|
-
|
|
180
|
-
Reflect.defineMetadata(argumentsKey, paramMetadata, target.constructor, methodName);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export const Query =
|
|
184
|
-
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
185
|
-
if (!methodName) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
190
|
-
|
|
191
|
-
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
192
|
-
index: parameterIndex,
|
|
193
|
-
type: queryArgsKey,
|
|
194
|
-
zodSchema: schema
|
|
195
|
-
} satisfies Extract<
|
|
196
|
-
TArgumentsMetadata,
|
|
197
|
-
{
|
|
198
|
-
type: typeof queryArgsKey;
|
|
199
|
-
}
|
|
200
|
-
>;
|
|
201
|
-
|
|
202
|
-
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export const Request =
|
|
206
|
-
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
207
|
-
if (!methodName) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const requestMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
212
|
-
|
|
213
|
-
requestMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
214
|
-
index: parameterIndex,
|
|
215
|
-
type: requestArgsKey,
|
|
216
|
-
zodSchema: schema
|
|
217
|
-
} satisfies Extract<
|
|
218
|
-
TArgumentsMetadata,
|
|
219
|
-
{
|
|
220
|
-
type: typeof requestArgsKey;
|
|
221
|
-
}
|
|
222
|
-
>;
|
|
223
|
-
|
|
224
|
-
Reflect.defineMetadata(argumentsKey, requestMetadata, target.constructor, methodName);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export const ResponseHeaders = () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
228
|
-
if (!methodName) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
233
|
-
|
|
234
|
-
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
235
|
-
index: parameterIndex,
|
|
236
|
-
type: responseHeadersArgsKey
|
|
237
|
-
} satisfies Extract<
|
|
238
|
-
TArgumentsMetadata,
|
|
239
|
-
{
|
|
240
|
-
type: typeof responseHeadersArgsKey;
|
|
241
|
-
}
|
|
242
|
-
>;
|
|
243
|
-
|
|
244
|
-
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
export const Context = (key?: symbol) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
248
|
-
if (!methodName) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
253
|
-
|
|
254
|
-
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
255
|
-
index: parameterIndex,
|
|
256
|
-
type: contextArgsKey,
|
|
257
|
-
key: key
|
|
258
|
-
} satisfies Extract<
|
|
259
|
-
TArgumentsMetadata,
|
|
260
|
-
{
|
|
261
|
-
type: typeof contextArgsKey;
|
|
262
|
-
}
|
|
263
|
-
>;
|
|
264
|
-
|
|
265
|
-
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export const RouteModel = () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
269
|
-
if (!methodName) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
274
|
-
|
|
275
|
-
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
276
|
-
index: parameterIndex,
|
|
277
|
-
type: routeModelArgsKey
|
|
278
|
-
} satisfies Extract<
|
|
279
|
-
TArgumentsMetadata,
|
|
280
|
-
{
|
|
281
|
-
type: typeof routeModelArgsKey;
|
|
282
|
-
}
|
|
283
|
-
>;
|
|
284
|
-
|
|
285
|
-
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
286
|
-
};
|
|
1
|
+
import * as Zod from "zod";
|
|
2
|
+
import {
|
|
3
|
+
argumentsKey,
|
|
4
|
+
contextArgsKey,
|
|
5
|
+
paramArgsKey,
|
|
6
|
+
paramsArgsKey,
|
|
7
|
+
queryArgsKey,
|
|
8
|
+
requestArgsKey,
|
|
9
|
+
requestBodyArgsKey,
|
|
10
|
+
requestHeaderArgsKey,
|
|
11
|
+
requestHeadersArgsKey,
|
|
12
|
+
responseHeadersArgsKey,
|
|
13
|
+
routeModelArgsKey
|
|
14
|
+
} from "../keys";
|
|
15
|
+
|
|
16
|
+
export type TArgumentsMetadata =
|
|
17
|
+
| {
|
|
18
|
+
index: number;
|
|
19
|
+
type: typeof requestHeadersArgsKey;
|
|
20
|
+
zodSchema?: Zod.Schema;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
index: number;
|
|
24
|
+
type: typeof requestHeaderArgsKey;
|
|
25
|
+
key: string;
|
|
26
|
+
zodSchema?: Zod.Schema;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
index: number;
|
|
30
|
+
type: typeof requestBodyArgsKey;
|
|
31
|
+
zodSchema?: Zod.Schema;
|
|
32
|
+
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
index: number;
|
|
36
|
+
type: typeof paramsArgsKey;
|
|
37
|
+
zodSchema?: Zod.Schema;
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
index: number;
|
|
41
|
+
type: typeof paramArgsKey;
|
|
42
|
+
key: string;
|
|
43
|
+
zodSchema?: Zod.Schema;
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
index: number;
|
|
47
|
+
type: typeof queryArgsKey;
|
|
48
|
+
zodSchema?: Zod.Schema;
|
|
49
|
+
}
|
|
50
|
+
| {
|
|
51
|
+
index: number;
|
|
52
|
+
type: typeof requestArgsKey;
|
|
53
|
+
zodSchema?: Zod.Schema;
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
index: number;
|
|
57
|
+
type: typeof responseHeadersArgsKey;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
index: number;
|
|
61
|
+
type: typeof contextArgsKey;
|
|
62
|
+
key?: symbol;
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
index: number;
|
|
66
|
+
type: typeof routeModelArgsKey;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const RequestHeaders =
|
|
70
|
+
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
71
|
+
if (!methodName) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const requestHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
76
|
+
|
|
77
|
+
requestHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
78
|
+
index: parameterIndex,
|
|
79
|
+
type: requestHeadersArgsKey,
|
|
80
|
+
zodSchema: schema
|
|
81
|
+
} satisfies Extract<
|
|
82
|
+
TArgumentsMetadata,
|
|
83
|
+
{
|
|
84
|
+
type: typeof requestHeadersArgsKey;
|
|
85
|
+
}
|
|
86
|
+
>;
|
|
87
|
+
|
|
88
|
+
Reflect.defineMetadata(argumentsKey, requestHeadersMetadata, target.constructor, methodName);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const RequestHeader =
|
|
92
|
+
(key: string, schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
93
|
+
if (!methodName) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const requestHeaderMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
98
|
+
|
|
99
|
+
requestHeaderMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
100
|
+
index: parameterIndex,
|
|
101
|
+
type: requestHeaderArgsKey,
|
|
102
|
+
key: key,
|
|
103
|
+
zodSchema: schema
|
|
104
|
+
} satisfies Extract<
|
|
105
|
+
TArgumentsMetadata,
|
|
106
|
+
{
|
|
107
|
+
type: typeof requestHeaderArgsKey;
|
|
108
|
+
}
|
|
109
|
+
>;
|
|
110
|
+
|
|
111
|
+
Reflect.defineMetadata(argumentsKey, requestHeaderMetadata, target.constructor, methodName);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const RequestBody =
|
|
115
|
+
(schema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") =>
|
|
116
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
117
|
+
if (!methodName) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
122
|
+
|
|
123
|
+
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
124
|
+
index: parameterIndex,
|
|
125
|
+
type: requestBodyArgsKey,
|
|
126
|
+
zodSchema: schema,
|
|
127
|
+
parser: parser
|
|
128
|
+
} satisfies Extract<
|
|
129
|
+
TArgumentsMetadata,
|
|
130
|
+
{
|
|
131
|
+
type: typeof requestBodyArgsKey;
|
|
132
|
+
}
|
|
133
|
+
>;
|
|
134
|
+
|
|
135
|
+
Reflect.defineMetadata(argumentsKey, bodyMetadata, target.constructor, methodName);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const Params =
|
|
139
|
+
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
140
|
+
if (!methodName) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
145
|
+
|
|
146
|
+
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
147
|
+
index: parameterIndex,
|
|
148
|
+
type: paramsArgsKey,
|
|
149
|
+
zodSchema: schema
|
|
150
|
+
} satisfies Extract<
|
|
151
|
+
TArgumentsMetadata,
|
|
152
|
+
{
|
|
153
|
+
type: typeof paramsArgsKey;
|
|
154
|
+
}
|
|
155
|
+
>;
|
|
156
|
+
|
|
157
|
+
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const Param =
|
|
161
|
+
(key: string, schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
162
|
+
if (!methodName) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const paramMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
167
|
+
|
|
168
|
+
paramMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
169
|
+
index: parameterIndex,
|
|
170
|
+
type: paramArgsKey,
|
|
171
|
+
key: key,
|
|
172
|
+
zodSchema: schema
|
|
173
|
+
} satisfies Extract<
|
|
174
|
+
TArgumentsMetadata,
|
|
175
|
+
{
|
|
176
|
+
type: typeof paramArgsKey;
|
|
177
|
+
}
|
|
178
|
+
>;
|
|
179
|
+
|
|
180
|
+
Reflect.defineMetadata(argumentsKey, paramMetadata, target.constructor, methodName);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const Query =
|
|
184
|
+
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
185
|
+
if (!methodName) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
190
|
+
|
|
191
|
+
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
192
|
+
index: parameterIndex,
|
|
193
|
+
type: queryArgsKey,
|
|
194
|
+
zodSchema: schema
|
|
195
|
+
} satisfies Extract<
|
|
196
|
+
TArgumentsMetadata,
|
|
197
|
+
{
|
|
198
|
+
type: typeof queryArgsKey;
|
|
199
|
+
}
|
|
200
|
+
>;
|
|
201
|
+
|
|
202
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export const Request =
|
|
206
|
+
(schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
207
|
+
if (!methodName) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const requestMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
212
|
+
|
|
213
|
+
requestMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
214
|
+
index: parameterIndex,
|
|
215
|
+
type: requestArgsKey,
|
|
216
|
+
zodSchema: schema
|
|
217
|
+
} satisfies Extract<
|
|
218
|
+
TArgumentsMetadata,
|
|
219
|
+
{
|
|
220
|
+
type: typeof requestArgsKey;
|
|
221
|
+
}
|
|
222
|
+
>;
|
|
223
|
+
|
|
224
|
+
Reflect.defineMetadata(argumentsKey, requestMetadata, target.constructor, methodName);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const ResponseHeaders = () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
228
|
+
if (!methodName) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
233
|
+
|
|
234
|
+
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
235
|
+
index: parameterIndex,
|
|
236
|
+
type: responseHeadersArgsKey
|
|
237
|
+
} satisfies Extract<
|
|
238
|
+
TArgumentsMetadata,
|
|
239
|
+
{
|
|
240
|
+
type: typeof responseHeadersArgsKey;
|
|
241
|
+
}
|
|
242
|
+
>;
|
|
243
|
+
|
|
244
|
+
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export const Context = (key?: symbol) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
248
|
+
if (!methodName) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
253
|
+
|
|
254
|
+
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
255
|
+
index: parameterIndex,
|
|
256
|
+
type: contextArgsKey,
|
|
257
|
+
key: key
|
|
258
|
+
} satisfies Extract<
|
|
259
|
+
TArgumentsMetadata,
|
|
260
|
+
{
|
|
261
|
+
type: typeof contextArgsKey;
|
|
262
|
+
}
|
|
263
|
+
>;
|
|
264
|
+
|
|
265
|
+
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export const RouteModel = () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
269
|
+
if (!methodName) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const responseHeadersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
274
|
+
|
|
275
|
+
responseHeadersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
276
|
+
index: parameterIndex,
|
|
277
|
+
type: routeModelArgsKey
|
|
278
|
+
} satisfies Extract<
|
|
279
|
+
TArgumentsMetadata,
|
|
280
|
+
{
|
|
281
|
+
type: typeof routeModelArgsKey;
|
|
282
|
+
}
|
|
283
|
+
>;
|
|
284
|
+
|
|
285
|
+
Reflect.defineMetadata(argumentsKey, responseHeadersMetadata, target.constructor, methodName);
|
|
286
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type { IController } from "../interfaces/controller";
|
|
2
|
-
import { controllerHttpKey, controllerKey } from "../keys";
|
|
3
|
-
import { type THttpMetadata } from "./http";
|
|
4
|
-
|
|
5
|
-
export type TControllerMetadata = Required<{
|
|
6
|
-
prefix: string;
|
|
7
|
-
httpMetadata: THttpMetadata;
|
|
8
|
-
}>;
|
|
9
|
-
|
|
10
|
-
export const Controller =
|
|
11
|
-
(prefix: string) =>
|
|
12
|
-
<T extends { new (...args: any[]): IController }>(target: T) => {
|
|
13
|
-
const metadata: TControllerMetadata = {
|
|
14
|
-
prefix: !prefix.startsWith("/") ? `/${prefix}` : prefix,
|
|
15
|
-
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || [])]
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Reflect.defineMetadata(controllerKey, metadata, target);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default Controller;
|
|
1
|
+
import type { IController } from "../interfaces/controller";
|
|
2
|
+
import { controllerHttpKey, controllerKey } from "../keys";
|
|
3
|
+
import { type THttpMetadata } from "./http";
|
|
4
|
+
|
|
5
|
+
export type TControllerMetadata = Required<{
|
|
6
|
+
prefix: string;
|
|
7
|
+
httpMetadata: THttpMetadata;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export const Controller =
|
|
11
|
+
(prefix: string) =>
|
|
12
|
+
<T extends { new (...args: any[]): IController }>(target: T) => {
|
|
13
|
+
const metadata: TControllerMetadata = {
|
|
14
|
+
prefix: !prefix.startsWith("/") ? `/${prefix}` : prefix,
|
|
15
|
+
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || [])]
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Reflect.defineMetadata(controllerKey, metadata, target);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default Controller;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import type { IDispatcher } from "../interfaces/dispatcher";
|
|
2
|
-
import { dispatcherKey } from "../keys";
|
|
3
|
-
|
|
4
|
-
export type TDispatcherMetadata = undefined;
|
|
5
|
-
|
|
6
|
-
export const Dispatcher =
|
|
7
|
-
() =>
|
|
8
|
-
<T extends { new (...args: any[]): IDispatcher }>(target: T) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Reflect.defineMetadata(dispatcherKey, metadata, target);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default Dispatcher;
|
|
1
|
+
import type { IDispatcher } from "../interfaces/dispatcher";
|
|
2
|
+
import { dispatcherKey } from "../keys";
|
|
3
|
+
|
|
4
|
+
export type TDispatcherMetadata = undefined;
|
|
5
|
+
|
|
6
|
+
export const Dispatcher =
|
|
7
|
+
() =>
|
|
8
|
+
<T extends { new (...args: any[]): IDispatcher }>(target: T) => {
|
|
9
|
+
const metadata: TDispatcherMetadata = undefined;
|
|
10
|
+
|
|
11
|
+
Reflect.defineMetadata(dispatcherKey, metadata, target);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default Dispatcher;
|