@bool-ts/core 1.8.2 → 1.9.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.
- package/__test/webSocket.ts +1 -1
- package/dist/decorators/arguments.d.ts +1 -0
- package/dist/decorators/container.d.ts +29 -0
- package/dist/decorators/http.d.ts +2 -0
- package/dist/decorators/webSocket.d.ts +2 -0
- package/dist/entities/httpRoute.d.ts +6 -0
- package/dist/hooks/factory.d.ts +2 -0
- package/dist/index.js +17 -4995
- package/dist/keys/index.d.ts +1 -0
- package/package.json +5 -5
- package/src/decorators/arguments.ts +100 -78
- package/src/decorators/container.ts +79 -0
- package/src/decorators/controller.ts +1 -1
- package/src/decorators/http.ts +9 -2
- package/src/decorators/module.ts +11 -2
- package/src/decorators/webSocket.ts +6 -2
- package/src/entities/httpRoute.ts +2 -0
- package/src/hooks/factory.ts +489 -487
- package/src/keys/index.ts +1 -0
package/dist/keys/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const injectKey: unique symbol;
|
|
|
9
9
|
export declare const injectableKey: unique symbol;
|
|
10
10
|
export declare const middlewareKey: unique symbol;
|
|
11
11
|
export declare const moduleKey: unique symbol;
|
|
12
|
+
export declare const containerKey: unique symbol;
|
|
12
13
|
export declare const zodSchemaKey: unique symbol;
|
|
13
14
|
export declare const webSocketKey: unique symbol;
|
|
14
15
|
export declare const webSocketEventKey: unique symbol;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bool-ts/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "bun --hot run __test/index.ts",
|
|
8
|
-
"build": "tsc --emitDeclarationOnly && bun build ./src/index.ts --outdir ./dist"
|
|
8
|
+
"build": "tsc --emitDeclarationOnly && bun build ./src/index.ts --outdir ./dist --minify"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"homepage": "https://github.com/BoolTS/core#readme",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@bool-ts/date-time": "^1.0.0",
|
|
22
|
-
"qs": "^6.
|
|
22
|
+
"qs": "^6.14.0",
|
|
23
23
|
"reflect-metadata": "^0.2.2",
|
|
24
24
|
"zod": "^3.24.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bun": "latest",
|
|
28
|
-
"@types/qs": "^6.9.
|
|
29
|
-
"typescript": "^5.7.
|
|
28
|
+
"@types/qs": "^6.9.18",
|
|
29
|
+
"typescript": "^5.7.3"
|
|
30
30
|
},
|
|
31
31
|
"private": "false"
|
|
32
32
|
}
|
|
@@ -66,15 +66,19 @@ export type TArgumentsMetadata =
|
|
|
66
66
|
type: typeof routeModelArgsKey;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
export type TArgumentsMetadataCollection = Record<`argumentIndexes.${number}`, TArgumentsMetadata>;
|
|
70
|
+
|
|
69
71
|
export const RequestHeaders =
|
|
70
|
-
(schema?: Zod.Schema) =>
|
|
72
|
+
(schema?: Zod.Schema) =>
|
|
73
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
71
74
|
if (!methodName) {
|
|
72
75
|
return;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
const
|
|
78
|
+
const metadata: TArgumentsMetadataCollection =
|
|
79
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
78
82
|
index: parameterIndex,
|
|
79
83
|
type: requestHeadersArgsKey,
|
|
80
84
|
zodSchema: schema
|
|
@@ -85,18 +89,20 @@ export const RequestHeaders =
|
|
|
85
89
|
}
|
|
86
90
|
>;
|
|
87
91
|
|
|
88
|
-
Reflect.defineMetadata(argumentsKey,
|
|
92
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
89
93
|
};
|
|
90
94
|
|
|
91
95
|
export const RequestHeader =
|
|
92
|
-
(key: string, schema?: Zod.Schema) =>
|
|
96
|
+
(key: string, schema?: Zod.Schema) =>
|
|
97
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
93
98
|
if (!methodName) {
|
|
94
99
|
return;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
const
|
|
102
|
+
const metadata: TArgumentsMetadataCollection =
|
|
103
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
100
106
|
index: parameterIndex,
|
|
101
107
|
type: requestHeaderArgsKey,
|
|
102
108
|
key: key,
|
|
@@ -108,7 +114,7 @@ export const RequestHeader =
|
|
|
108
114
|
}
|
|
109
115
|
>;
|
|
110
116
|
|
|
111
|
-
Reflect.defineMetadata(argumentsKey,
|
|
117
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
112
118
|
};
|
|
113
119
|
|
|
114
120
|
export const RequestBody =
|
|
@@ -118,9 +124,10 @@ export const RequestBody =
|
|
|
118
124
|
return;
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
const
|
|
127
|
+
const metadata: TArgumentsMetadataCollection =
|
|
128
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
122
129
|
|
|
123
|
-
|
|
130
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
124
131
|
index: parameterIndex,
|
|
125
132
|
type: requestBodyArgsKey,
|
|
126
133
|
zodSchema: schema,
|
|
@@ -132,18 +139,20 @@ export const RequestBody =
|
|
|
132
139
|
}
|
|
133
140
|
>;
|
|
134
141
|
|
|
135
|
-
Reflect.defineMetadata(argumentsKey,
|
|
142
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
136
143
|
};
|
|
137
144
|
|
|
138
145
|
export const Params =
|
|
139
|
-
(schema?: Zod.Schema) =>
|
|
146
|
+
(schema?: Zod.Schema) =>
|
|
147
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
140
148
|
if (!methodName) {
|
|
141
149
|
return;
|
|
142
150
|
}
|
|
143
151
|
|
|
144
|
-
const
|
|
152
|
+
const metadata: TArgumentsMetadataCollection =
|
|
153
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
145
154
|
|
|
146
|
-
|
|
155
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
147
156
|
index: parameterIndex,
|
|
148
157
|
type: paramsArgsKey,
|
|
149
158
|
zodSchema: schema
|
|
@@ -154,18 +163,20 @@ export const Params =
|
|
|
154
163
|
}
|
|
155
164
|
>;
|
|
156
165
|
|
|
157
|
-
Reflect.defineMetadata(argumentsKey,
|
|
166
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
158
167
|
};
|
|
159
168
|
|
|
160
169
|
export const Param =
|
|
161
|
-
(key: string, schema?: Zod.Schema) =>
|
|
170
|
+
(key: string, schema?: Zod.Schema) =>
|
|
171
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
162
172
|
if (!methodName) {
|
|
163
173
|
return;
|
|
164
174
|
}
|
|
165
175
|
|
|
166
|
-
const
|
|
176
|
+
const metadata: TArgumentsMetadataCollection =
|
|
177
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
167
178
|
|
|
168
|
-
|
|
179
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
169
180
|
index: parameterIndex,
|
|
170
181
|
type: paramArgsKey,
|
|
171
182
|
key: key,
|
|
@@ -177,18 +188,20 @@ export const Param =
|
|
|
177
188
|
}
|
|
178
189
|
>;
|
|
179
190
|
|
|
180
|
-
Reflect.defineMetadata(argumentsKey,
|
|
191
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
181
192
|
};
|
|
182
193
|
|
|
183
194
|
export const Query =
|
|
184
|
-
(schema?: Zod.Schema) =>
|
|
195
|
+
(schema?: Zod.Schema) =>
|
|
196
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
185
197
|
if (!methodName) {
|
|
186
198
|
return;
|
|
187
199
|
}
|
|
188
200
|
|
|
189
|
-
const
|
|
201
|
+
const metadata: TArgumentsMetadataCollection =
|
|
202
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
190
203
|
|
|
191
|
-
|
|
204
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
192
205
|
index: parameterIndex,
|
|
193
206
|
type: queryArgsKey,
|
|
194
207
|
zodSchema: schema
|
|
@@ -199,18 +212,20 @@ export const Query =
|
|
|
199
212
|
}
|
|
200
213
|
>;
|
|
201
214
|
|
|
202
|
-
Reflect.defineMetadata(argumentsKey,
|
|
215
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
203
216
|
};
|
|
204
217
|
|
|
205
218
|
export const Request =
|
|
206
|
-
(schema?: Zod.Schema) =>
|
|
219
|
+
(schema?: Zod.Schema) =>
|
|
220
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
207
221
|
if (!methodName) {
|
|
208
222
|
return;
|
|
209
223
|
}
|
|
210
224
|
|
|
211
|
-
const
|
|
225
|
+
const metadata: TArgumentsMetadataCollection =
|
|
226
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
212
227
|
|
|
213
|
-
|
|
228
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
214
229
|
index: parameterIndex,
|
|
215
230
|
type: requestArgsKey,
|
|
216
231
|
zodSchema: schema
|
|
@@ -221,66 +236,73 @@ export const Request =
|
|
|
221
236
|
}
|
|
222
237
|
>;
|
|
223
238
|
|
|
224
|
-
Reflect.defineMetadata(argumentsKey,
|
|
239
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
225
240
|
};
|
|
226
241
|
|
|
227
|
-
export const ResponseHeaders =
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
242
|
+
export const ResponseHeaders =
|
|
243
|
+
() => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
244
|
+
if (!methodName) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
231
247
|
|
|
232
|
-
|
|
248
|
+
const metadata: TArgumentsMetadataCollection =
|
|
249
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
233
250
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
export const Context =
|
|
248
|
-
|
|
249
|
-
|
|
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;
|
|
251
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
252
|
+
index: parameterIndex,
|
|
253
|
+
type: responseHeadersArgsKey
|
|
254
|
+
} satisfies Extract<
|
|
255
|
+
TArgumentsMetadata,
|
|
256
|
+
{
|
|
257
|
+
type: typeof responseHeadersArgsKey;
|
|
258
|
+
}
|
|
259
|
+
>;
|
|
260
|
+
|
|
261
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export const Context =
|
|
265
|
+
(key?: symbol) =>
|
|
266
|
+
(target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
267
|
+
if (!methodName) {
|
|
268
|
+
return;
|
|
262
269
|
}
|
|
263
|
-
>;
|
|
264
270
|
|
|
265
|
-
|
|
266
|
-
};
|
|
271
|
+
const metadata: TArgumentsMetadataCollection =
|
|
272
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
267
273
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
274
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
275
|
+
index: parameterIndex,
|
|
276
|
+
type: contextArgsKey,
|
|
277
|
+
key: key
|
|
278
|
+
} satisfies Extract<
|
|
279
|
+
TArgumentsMetadata,
|
|
280
|
+
{
|
|
281
|
+
type: typeof contextArgsKey;
|
|
282
|
+
}
|
|
283
|
+
>;
|
|
272
284
|
|
|
273
|
-
|
|
285
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
286
|
+
};
|
|
274
287
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
TArgumentsMetadata,
|
|
280
|
-
{
|
|
281
|
-
type: typeof routeModelArgsKey;
|
|
288
|
+
export const RouteModel =
|
|
289
|
+
() => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
290
|
+
if (!methodName) {
|
|
291
|
+
return;
|
|
282
292
|
}
|
|
283
|
-
>;
|
|
284
293
|
|
|
285
|
-
|
|
286
|
-
};
|
|
294
|
+
const metadata: TArgumentsMetadataCollection =
|
|
295
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
296
|
+
|
|
297
|
+
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
298
|
+
index: parameterIndex,
|
|
299
|
+
type: routeModelArgsKey
|
|
300
|
+
} satisfies Extract<
|
|
301
|
+
TArgumentsMetadata,
|
|
302
|
+
{
|
|
303
|
+
type: typeof routeModelArgsKey;
|
|
304
|
+
}
|
|
305
|
+
>;
|
|
306
|
+
|
|
307
|
+
Reflect.defineMetadata(argumentsKey, metadata, target.constructor, methodName);
|
|
308
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { IModule } from "../interfaces";
|
|
2
|
+
|
|
3
|
+
import { containerKey, dispatcherKey, guardKey, injectableKey, middlewareKey } from "../keys";
|
|
4
|
+
|
|
5
|
+
type TInstances = Array<new (...args: any[]) => any>;
|
|
6
|
+
type TLoaders<TConfig extends {} = {}> = Record<
|
|
7
|
+
string | symbol,
|
|
8
|
+
(args: { config: TConfig }) => [string | symbol, any] | Promise<[string | symbol, any]>
|
|
9
|
+
>;
|
|
10
|
+
|
|
11
|
+
export type TContainerOptions<TConfig extends {} = {}> =
|
|
12
|
+
| (Required<{
|
|
13
|
+
modules: TInstances;
|
|
14
|
+
}> &
|
|
15
|
+
Partial<{
|
|
16
|
+
config: TConfig | (() => TConfig | Promise<TConfig>);
|
|
17
|
+
dependencies: TInstances;
|
|
18
|
+
loaders: TLoaders<TConfig>;
|
|
19
|
+
middlewares: TInstances;
|
|
20
|
+
guards: TInstances;
|
|
21
|
+
dispatchers: TInstances;
|
|
22
|
+
}>)
|
|
23
|
+
| undefined;
|
|
24
|
+
|
|
25
|
+
export type TContainerMetadata<TConfig extends {} = {}> =
|
|
26
|
+
| (Required<{
|
|
27
|
+
modules: TInstances;
|
|
28
|
+
}> &
|
|
29
|
+
Partial<{
|
|
30
|
+
config: TConfig | ((...args: any[]) => TConfig | Promise<TConfig>);
|
|
31
|
+
dependencies: TInstances;
|
|
32
|
+
loaders: TLoaders<TConfig>;
|
|
33
|
+
middlewares: TInstances;
|
|
34
|
+
guards: TInstances;
|
|
35
|
+
dispatchers: TInstances;
|
|
36
|
+
}>)
|
|
37
|
+
| undefined;
|
|
38
|
+
|
|
39
|
+
export const Container =
|
|
40
|
+
<TConfig extends {} = {}>(args?: TContainerOptions<TConfig>) =>
|
|
41
|
+
<T extends { new (...args: any[]): IModule }>(target: T) => {
|
|
42
|
+
const { middlewares, guards, dispatchers, dependencies } = args || {};
|
|
43
|
+
|
|
44
|
+
if (middlewares) {
|
|
45
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
46
|
+
if (!Reflect.getOwnMetadataKeys(middlewares[i]).includes(middlewareKey)) {
|
|
47
|
+
throw Error(`${middlewares[i].name} is not a middleware.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (guards) {
|
|
53
|
+
for (let i = 0; i < guards.length; i++) {
|
|
54
|
+
if (!Reflect.getOwnMetadataKeys(guards[i]).includes(guardKey)) {
|
|
55
|
+
throw Error(`${guards[i].name} is not a guard.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (dispatchers) {
|
|
61
|
+
for (let i = 0; i < dispatchers.length; i++) {
|
|
62
|
+
if (!Reflect.getOwnMetadataKeys(dispatchers[i]).includes(dispatcherKey)) {
|
|
63
|
+
throw Error(`${dispatchers[i].name} is not a dispatcher.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (dependencies) {
|
|
69
|
+
for (let i = 0; i < dependencies.length; i++) {
|
|
70
|
+
if (!Reflect.getOwnMetadataKeys(dependencies[i]).includes(injectableKey)) {
|
|
71
|
+
throw Error(`${dependencies[i].name} is not an injectable.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Reflect.defineMetadata(containerKey, args, target);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default Container;
|
|
@@ -13,7 +13,7 @@ export const Controller =
|
|
|
13
13
|
<T extends { new (...args: any[]): IController }>(target: T) => {
|
|
14
14
|
const metadata: TControllerMetadata = {
|
|
15
15
|
prefix: !prefix?.startsWith("/") ? `/${prefix || ""}` : prefix,
|
|
16
|
-
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target
|
|
16
|
+
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target) || [])]
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
Reflect.defineMetadata(controllerKey, metadata, target);
|
package/src/decorators/http.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TArgumentsMetadataCollection } from "./arguments";
|
|
2
|
+
|
|
3
|
+
import { argumentsKey, controllerHttpKey } from "../keys";
|
|
2
4
|
|
|
3
5
|
export type TRoute = {
|
|
4
6
|
path: string;
|
|
5
7
|
httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
6
8
|
methodName: string;
|
|
7
9
|
descriptor: TypedPropertyDescriptor<any>;
|
|
10
|
+
argumentsMetadata: TArgumentsMetadataCollection;
|
|
8
11
|
};
|
|
9
12
|
|
|
10
13
|
export type THttpMetadata = Array<TRoute>;
|
|
@@ -16,13 +19,17 @@ const defaultDecorator =
|
|
|
16
19
|
throw Error(`${method} decorator only use for class method.`);
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
const argumentsMetadata: TArgumentsMetadataCollection =
|
|
23
|
+
Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
24
|
+
|
|
19
25
|
const metadata: THttpMetadata = [
|
|
20
26
|
...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || []),
|
|
21
27
|
{
|
|
22
28
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
23
29
|
httpMethod: method.toUpperCase(),
|
|
24
30
|
methodName: methodName,
|
|
25
|
-
descriptor: descriptor
|
|
31
|
+
descriptor: descriptor,
|
|
32
|
+
argumentsMetadata: argumentsMetadata
|
|
26
33
|
}
|
|
27
34
|
];
|
|
28
35
|
|
package/src/decorators/module.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { IModule } from "../interfaces";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
controllerKey,
|
|
5
|
+
dispatcherKey,
|
|
6
|
+
guardKey,
|
|
7
|
+
injectableKey,
|
|
8
|
+
middlewareKey,
|
|
9
|
+
moduleKey,
|
|
10
|
+
webSocketKey
|
|
11
|
+
} from "../keys";
|
|
4
12
|
|
|
5
13
|
type TInstances = Array<new (...args: any[]) => any>;
|
|
6
14
|
type TLoaders<TConfig extends {} = {}> = Record<
|
|
@@ -39,7 +47,8 @@ export type TModuleMetadata<TConfig extends {} = {}> =
|
|
|
39
47
|
export const Module =
|
|
40
48
|
<TConfig extends {} = {}>(args?: TModuleOptions<TConfig>) =>
|
|
41
49
|
<T extends { new (...args: any[]): IModule }>(target: T) => {
|
|
42
|
-
const { middlewares, guards, dispatchers, controllers, dependencies, webSockets } =
|
|
50
|
+
const { middlewares, guards, dispatchers, controllers, dependencies, webSockets } =
|
|
51
|
+
args || {};
|
|
43
52
|
|
|
44
53
|
if (middlewares) {
|
|
45
54
|
for (let i = 0; i < middlewares.length; i++) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Server } from "bun";
|
|
2
2
|
import type { IWebSocket } from "../interfaces";
|
|
3
|
+
import type { TArgumentsMetadataCollection } from "./arguments";
|
|
3
4
|
import type { TWebSocketEventMetadata } from "./webSocketEvent";
|
|
4
5
|
|
|
5
6
|
import { webSocketEventKey, webSocketKey } from "../keys";
|
|
@@ -9,6 +10,7 @@ export type TWebSocketHttpRouteMetadata = {
|
|
|
9
10
|
httpMethod: "GET" | "POST";
|
|
10
11
|
methodName: symbol;
|
|
11
12
|
descriptor: PropertyDescriptor;
|
|
13
|
+
argumentsMetadata: TArgumentsMetadataCollection;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export type TWebSocketUpgradeData = {
|
|
@@ -59,13 +61,15 @@ export const WebSocket =
|
|
|
59
61
|
path: "/",
|
|
60
62
|
httpMethod: "GET",
|
|
61
63
|
methodName: upgradeHandlerSymbol,
|
|
62
|
-
descriptor: descriptor
|
|
64
|
+
descriptor: descriptor,
|
|
65
|
+
argumentsMetadata: {}
|
|
63
66
|
},
|
|
64
67
|
{
|
|
65
68
|
path: "/",
|
|
66
69
|
httpMethod: "POST",
|
|
67
70
|
methodName: upgradeHandlerSymbol,
|
|
68
|
-
descriptor: descriptor
|
|
71
|
+
descriptor: descriptor,
|
|
72
|
+
argumentsMetadata: {}
|
|
69
73
|
}
|
|
70
74
|
];
|
|
71
75
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import type { TArgumentsMetadataCollection } from "../decorators/arguments";
|
|
3
4
|
import type { THttpMethods } from "../http";
|
|
4
5
|
|
|
5
6
|
export type THttpRouteModel<T = unknown> = Readonly<{
|
|
6
7
|
class: new (...args: Array<any>) => T;
|
|
7
8
|
funcName: string | symbol;
|
|
8
9
|
func: (...args: Array<any>) => unknown;
|
|
10
|
+
argumentsMetadata: TArgumentsMetadataCollection;
|
|
9
11
|
}>;
|
|
10
12
|
|
|
11
13
|
export class HttpRoute {
|