@bool-ts/core 1.9.28 → 2.0.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/dist/decorators/arguments.d.ts +19 -20
- package/dist/decorators/container.d.ts +10 -11
- package/dist/decorators/http.d.ts +11 -11
- package/dist/decorators/index.d.ts +1 -2
- package/dist/entities/application.d.ts +111 -0
- package/dist/{producers → entities}/context.d.ts +1 -0
- package/dist/entities/httpRoute.d.ts +18 -9
- package/dist/entities/httpRouter.d.ts +13 -0
- package/dist/entities/httpRouterGroup.d.ts +6 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/validationFailed.d.ts +5 -0
- package/dist/entities/webSocketRoute.d.ts +1 -0
- package/dist/entities/webSocketRouter.d.ts +1 -0
- package/dist/entities/webSocketRouterGroup.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -7
- package/dist/index.js.map +23 -21
- package/dist/interfaces/customValidator.d.ts +4 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/producers/factory.d.ts +3 -1
- package/dist/producers/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/decorators/arguments.ts +44 -39
- package/src/decorators/container.ts +12 -12
- package/src/decorators/http.ts +8 -8
- package/src/decorators/index.ts +1 -2
- package/src/entities/application.ts +2236 -0
- package/src/{producers → entities}/context.ts +2 -0
- package/src/entities/httpRoute.ts +18 -9
- package/src/entities/httpRouter.ts +13 -0
- package/src/entities/httpRouterGroup.ts +10 -4
- package/src/entities/index.ts +2 -0
- package/src/entities/validationFailed.ts +5 -0
- package/src/entities/webSocketRoute.ts +2 -0
- package/src/entities/webSocketRouter.ts +2 -0
- package/src/entities/webSocketRouterGroup.ts +2 -0
- package/src/index.ts +1 -0
- package/src/interfaces/customValidator.ts +10 -0
- package/src/interfaces/index.ts +1 -0
- package/src/producers/factory.ts +7 -2037
- package/src/producers/index.ts +1 -1
- package/dist/decorators/zodSchema.d.ts +0 -2
- package/src/decorators/zodSchema.ts +0 -21
- /package/dist/{producers → entities}/injector.d.ts +0 -0
- /package/src/{producers → entities}/injector.ts +0 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ValidationFailed } from "../entities";
|
|
2
|
+
export interface ICustomValidator<TValidData = unknown, TValidationSchema = unknown> {
|
|
3
|
+
validate(data: unknown, validationSchema: TValidationSchema, argumentIndex: number, funcName: string | symbol): (TValidData | ValidationFailed) | Promise<TValidData | ValidationFailed>;
|
|
4
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { IContainer } from "./container";
|
|
2
2
|
export type { IContext, TContextOptions } from "./context";
|
|
3
3
|
export type { IController } from "./controller";
|
|
4
|
+
export type { ICustomValidator } from "./customValidator";
|
|
4
5
|
export type { IGuard } from "./guard";
|
|
5
6
|
export type { IInterceptor } from "./interceptor";
|
|
6
7
|
export type { IMiddleware } from "./middleware";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { TArgumentsMetadataCollection } from "../decorators/arguments";
|
|
2
|
+
import type { TConstructor } from "../ultils";
|
|
2
3
|
import "reflect-metadata";
|
|
3
4
|
import Qs from "qs";
|
|
5
|
+
import { Application } from "../entities";
|
|
4
6
|
export type TParamsType = Record<string, string>;
|
|
5
7
|
export type TGroupElementModel<TFuncName extends keyof TClass, TClass extends Object = Object, TFunc = TClass[TFuncName]> = Readonly<{
|
|
6
8
|
class: TClass;
|
|
@@ -31,5 +33,5 @@ export type TBoolFactoryOptions = Required<{
|
|
|
31
33
|
headers: Array<string>;
|
|
32
34
|
}>;
|
|
33
35
|
}>;
|
|
34
|
-
export declare const BoolFactory:
|
|
36
|
+
export declare const BoolFactory: <T extends Object>(classConstructor: TConstructor<T>, options: TBoolFactoryOptions) => Promise<Application<T>>;
|
|
35
37
|
export default BoolFactory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bool-ts/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Core package for BoolTS framework",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "bun --hot run __test/index.ts",
|
|
20
|
-
"build": "tsc --emitDeclarationOnly && bun
|
|
20
|
+
"build": "tsc --emitDeclarationOnly && bun run app.build.ts"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@bool-ts/date-time": "^1.0.0",
|
|
34
34
|
"qs": "^6.14.0",
|
|
35
35
|
"reflect-metadata": "^0.2.2",
|
|
36
|
-
"zod": "^3.25.
|
|
36
|
+
"zod": "^3.25.67"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/bun": "latest",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Zod from "zod";
|
|
2
1
|
import {
|
|
3
2
|
argumentsKey,
|
|
4
3
|
contextArgsKey,
|
|
@@ -14,44 +13,44 @@ import {
|
|
|
14
13
|
routeModelArgsKey
|
|
15
14
|
} from "../keys";
|
|
16
15
|
|
|
17
|
-
export type TArgumentsMetadata =
|
|
16
|
+
export type TArgumentsMetadata<TValidationSchema = unknown> =
|
|
18
17
|
| {
|
|
19
18
|
index: number;
|
|
20
19
|
type: typeof requestHeadersArgsKey;
|
|
21
|
-
|
|
20
|
+
validationSchema?: TValidationSchema;
|
|
22
21
|
}
|
|
23
22
|
| {
|
|
24
23
|
index: number;
|
|
25
24
|
type: typeof requestHeaderArgsKey;
|
|
26
25
|
key: string;
|
|
27
|
-
|
|
26
|
+
validationSchema?: TValidationSchema;
|
|
28
27
|
}
|
|
29
28
|
| {
|
|
30
29
|
index: number;
|
|
31
30
|
type: typeof requestBodyArgsKey;
|
|
32
|
-
|
|
31
|
+
validationSchema?: TValidationSchema;
|
|
33
32
|
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
34
33
|
}
|
|
35
34
|
| {
|
|
36
35
|
index: number;
|
|
37
36
|
type: typeof paramsArgsKey;
|
|
38
|
-
|
|
37
|
+
validationSchema?: TValidationSchema;
|
|
39
38
|
}
|
|
40
39
|
| {
|
|
41
40
|
index: number;
|
|
42
41
|
type: typeof paramArgsKey;
|
|
43
42
|
key: string;
|
|
44
|
-
|
|
43
|
+
validationSchema?: TValidationSchema;
|
|
45
44
|
}
|
|
46
45
|
| {
|
|
47
46
|
index: number;
|
|
48
47
|
type: typeof queryArgsKey;
|
|
49
|
-
|
|
48
|
+
validationSchema?: TValidationSchema;
|
|
50
49
|
}
|
|
51
50
|
| {
|
|
52
51
|
index: number;
|
|
53
52
|
type: typeof requestArgsKey;
|
|
54
|
-
|
|
53
|
+
validationSchema?: TValidationSchema;
|
|
55
54
|
}
|
|
56
55
|
| {
|
|
57
56
|
index: number;
|
|
@@ -74,8 +73,8 @@ export type TArgumentsMetadata =
|
|
|
74
73
|
export type TArgumentsMetadataCollection = Record<`argumentIndexes.${number}`, TArgumentsMetadata>;
|
|
75
74
|
|
|
76
75
|
export const RequestHeaders =
|
|
77
|
-
<
|
|
78
|
-
(target:
|
|
76
|
+
<TTarget extends Object, TValidationSchema = unknown>(validationSchema?: TValidationSchema) =>
|
|
77
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
79
78
|
if (!methodName) {
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
@@ -86,7 +85,7 @@ export const RequestHeaders =
|
|
|
86
85
|
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
87
86
|
index: parameterIndex,
|
|
88
87
|
type: requestHeadersArgsKey,
|
|
89
|
-
|
|
88
|
+
validationSchema: validationSchema
|
|
90
89
|
} satisfies Extract<
|
|
91
90
|
TArgumentsMetadata,
|
|
92
91
|
{
|
|
@@ -98,8 +97,11 @@ export const RequestHeaders =
|
|
|
98
97
|
};
|
|
99
98
|
|
|
100
99
|
export const RequestHeader =
|
|
101
|
-
<
|
|
102
|
-
|
|
100
|
+
<TTarget extends Object, TValidationSchema = unknown>(
|
|
101
|
+
key: string,
|
|
102
|
+
validationSchema?: TValidationSchema
|
|
103
|
+
) =>
|
|
104
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
103
105
|
if (!methodName) {
|
|
104
106
|
return;
|
|
105
107
|
}
|
|
@@ -111,7 +113,7 @@ export const RequestHeader =
|
|
|
111
113
|
index: parameterIndex,
|
|
112
114
|
type: requestHeaderArgsKey,
|
|
113
115
|
key: key,
|
|
114
|
-
|
|
116
|
+
validationSchema: validationSchema
|
|
115
117
|
} satisfies Extract<
|
|
116
118
|
TArgumentsMetadata,
|
|
117
119
|
{
|
|
@@ -123,11 +125,11 @@ export const RequestHeader =
|
|
|
123
125
|
};
|
|
124
126
|
|
|
125
127
|
export const RequestBody =
|
|
126
|
-
<
|
|
127
|
-
|
|
128
|
+
<TTarget extends Object, TValidationSchema = unknown>(
|
|
129
|
+
validationSchema?: TValidationSchema,
|
|
128
130
|
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text"
|
|
129
131
|
) =>
|
|
130
|
-
(target:
|
|
132
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
131
133
|
if (!methodName) {
|
|
132
134
|
return;
|
|
133
135
|
}
|
|
@@ -138,7 +140,7 @@ export const RequestBody =
|
|
|
138
140
|
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
139
141
|
index: parameterIndex,
|
|
140
142
|
type: requestBodyArgsKey,
|
|
141
|
-
|
|
143
|
+
validationSchema: validationSchema,
|
|
142
144
|
parser: parser
|
|
143
145
|
} satisfies Extract<
|
|
144
146
|
TArgumentsMetadata,
|
|
@@ -151,8 +153,8 @@ export const RequestBody =
|
|
|
151
153
|
};
|
|
152
154
|
|
|
153
155
|
export const Params =
|
|
154
|
-
<
|
|
155
|
-
(target:
|
|
156
|
+
<TTarget extends Object, TValidationSchema = unknown>(validationSchema?: TValidationSchema) =>
|
|
157
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
156
158
|
if (!methodName) {
|
|
157
159
|
return;
|
|
158
160
|
}
|
|
@@ -163,7 +165,7 @@ export const Params =
|
|
|
163
165
|
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
164
166
|
index: parameterIndex,
|
|
165
167
|
type: paramsArgsKey,
|
|
166
|
-
|
|
168
|
+
validationSchema: validationSchema
|
|
167
169
|
} satisfies Extract<
|
|
168
170
|
TArgumentsMetadata,
|
|
169
171
|
{
|
|
@@ -175,8 +177,11 @@ export const Params =
|
|
|
175
177
|
};
|
|
176
178
|
|
|
177
179
|
export const Param =
|
|
178
|
-
<
|
|
179
|
-
|
|
180
|
+
<TTarget extends Object, TValidationSchema = unknown>(
|
|
181
|
+
key: string,
|
|
182
|
+
validationSchema?: TValidationSchema
|
|
183
|
+
) =>
|
|
184
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
180
185
|
if (!methodName) {
|
|
181
186
|
return;
|
|
182
187
|
}
|
|
@@ -188,7 +193,7 @@ export const Param =
|
|
|
188
193
|
index: parameterIndex,
|
|
189
194
|
type: paramArgsKey,
|
|
190
195
|
key: key,
|
|
191
|
-
|
|
196
|
+
validationSchema: validationSchema
|
|
192
197
|
} satisfies Extract<
|
|
193
198
|
TArgumentsMetadata,
|
|
194
199
|
{
|
|
@@ -200,8 +205,8 @@ export const Param =
|
|
|
200
205
|
};
|
|
201
206
|
|
|
202
207
|
export const Query =
|
|
203
|
-
<
|
|
204
|
-
(target:
|
|
208
|
+
<TTarget extends Object, TValidationSchema = unknown>(validationSchema?: TValidationSchema) =>
|
|
209
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
205
210
|
if (!methodName) {
|
|
206
211
|
return;
|
|
207
212
|
}
|
|
@@ -212,7 +217,7 @@ export const Query =
|
|
|
212
217
|
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
213
218
|
index: parameterIndex,
|
|
214
219
|
type: queryArgsKey,
|
|
215
|
-
|
|
220
|
+
validationSchema: validationSchema
|
|
216
221
|
} satisfies Extract<
|
|
217
222
|
TArgumentsMetadata,
|
|
218
223
|
{
|
|
@@ -224,8 +229,8 @@ export const Query =
|
|
|
224
229
|
};
|
|
225
230
|
|
|
226
231
|
export const Request =
|
|
227
|
-
<
|
|
228
|
-
(target:
|
|
232
|
+
<TTarget extends Object, TValidationSchema = unknown>(validationSchema?: TValidationSchema) =>
|
|
233
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
229
234
|
if (!methodName) {
|
|
230
235
|
return;
|
|
231
236
|
}
|
|
@@ -236,7 +241,7 @@ export const Request =
|
|
|
236
241
|
metadata[`argumentIndexes.${parameterIndex}`] = {
|
|
237
242
|
index: parameterIndex,
|
|
238
243
|
type: requestArgsKey,
|
|
239
|
-
|
|
244
|
+
validationSchema: validationSchema
|
|
240
245
|
} satisfies Extract<
|
|
241
246
|
TArgumentsMetadata,
|
|
242
247
|
{
|
|
@@ -248,8 +253,8 @@ export const Request =
|
|
|
248
253
|
};
|
|
249
254
|
|
|
250
255
|
export const ResponseHeaders =
|
|
251
|
-
<
|
|
252
|
-
(target:
|
|
256
|
+
<TTarget extends Object>() =>
|
|
257
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
253
258
|
if (!methodName) {
|
|
254
259
|
return;
|
|
255
260
|
}
|
|
@@ -271,8 +276,8 @@ export const ResponseHeaders =
|
|
|
271
276
|
};
|
|
272
277
|
|
|
273
278
|
export const Context =
|
|
274
|
-
<
|
|
275
|
-
(target:
|
|
279
|
+
<TTarget extends Object>(key?: symbol) =>
|
|
280
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
276
281
|
if (!methodName) {
|
|
277
282
|
return;
|
|
278
283
|
}
|
|
@@ -295,8 +300,8 @@ export const Context =
|
|
|
295
300
|
};
|
|
296
301
|
|
|
297
302
|
export const RouteModel =
|
|
298
|
-
<
|
|
299
|
-
(target:
|
|
303
|
+
<TTarget extends Object>() =>
|
|
304
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
300
305
|
if (!methodName) {
|
|
301
306
|
return;
|
|
302
307
|
}
|
|
@@ -318,8 +323,8 @@ export const RouteModel =
|
|
|
318
323
|
};
|
|
319
324
|
|
|
320
325
|
export const HttpServer =
|
|
321
|
-
<
|
|
322
|
-
(target:
|
|
326
|
+
<TTarget extends Object>() =>
|
|
327
|
+
(target: TTarget, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
323
328
|
if (!methodName) {
|
|
324
329
|
return;
|
|
325
330
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { containerKey, guardKey, injectableKey, middlewareKey, moduleKey } from "../keys";
|
|
2
1
|
import type { TConstructor } from "../ultils";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { containerKey, guardKey, injectableKey, middlewareKey, moduleKey } from "../keys";
|
|
4
|
+
|
|
5
5
|
type TLoaders<TConfig extends {} = {}> = Record<
|
|
6
6
|
string | symbol,
|
|
7
7
|
(args: { config: TConfig }) => [string | symbol, any] | Promise<[string | symbol, any]>
|
|
@@ -16,23 +16,23 @@ export type TContainerConfig<TConfig> =
|
|
|
16
16
|
|
|
17
17
|
export type TContainerOptions<TConfig extends {} = {}> =
|
|
18
18
|
| Partial<{
|
|
19
|
-
config: TContainerConfig<TConfig>;
|
|
20
|
-
modules: TInstances;
|
|
21
|
-
dependencies: TInstances;
|
|
22
19
|
loaders: TLoaders<TConfig>;
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
config: TContainerConfig<TConfig>;
|
|
21
|
+
modules: Array<TConstructor<unknown>>;
|
|
22
|
+
dependencies: Array<TConstructor<unknown>>;
|
|
23
|
+
middlewares: Array<TConstructor<unknown>>;
|
|
24
|
+
guards: Array<TConstructor<unknown>>;
|
|
25
25
|
}>
|
|
26
26
|
| undefined;
|
|
27
27
|
|
|
28
28
|
export type TContainerMetadata<TConfig extends {} = {}> =
|
|
29
29
|
| Partial<{
|
|
30
|
-
modules: TInstances;
|
|
31
|
-
config: TContainerConfig<TConfig>;
|
|
32
|
-
dependencies: TInstances;
|
|
33
30
|
loaders: TLoaders<TConfig>;
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
config: TContainerConfig<TConfig>;
|
|
32
|
+
modules: Array<TConstructor<unknown>>;
|
|
33
|
+
dependencies: Array<TConstructor<unknown>>;
|
|
34
|
+
middlewares: Array<TConstructor<unknown>>;
|
|
35
|
+
guards: Array<TConstructor<unknown>>;
|
|
36
36
|
}>
|
|
37
37
|
| undefined;
|
|
38
38
|
|
package/src/decorators/http.ts
CHANGED
|
@@ -13,11 +13,11 @@ export type TRoute = {
|
|
|
13
13
|
export type THttpMetadata = Array<TRoute>;
|
|
14
14
|
|
|
15
15
|
const defaultDecorator =
|
|
16
|
-
<T
|
|
16
|
+
<T extends Object, K>(
|
|
17
17
|
path: string,
|
|
18
18
|
method: "Get" | "Post" | "Put" | "Patch" | "Delete" | "Options"
|
|
19
19
|
) =>
|
|
20
|
-
(target:
|
|
20
|
+
(target: T, methodName: string | symbol, descriptor: TypedPropertyDescriptor<K>) => {
|
|
21
21
|
if (!(descriptor?.value instanceof Function)) {
|
|
22
22
|
throw Error(`${method} decorator only use for class method.`);
|
|
23
23
|
}
|
|
@@ -45,42 +45,42 @@ const defaultDecorator =
|
|
|
45
45
|
* @param path
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
|
-
export const Get = <T
|
|
48
|
+
export const Get = <T extends Object, K>(path = "/") => defaultDecorator<T, K>(path, "Get");
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
*
|
|
52
52
|
* @param path
|
|
53
53
|
* @returns
|
|
54
54
|
*/
|
|
55
|
-
export const Post = <T
|
|
55
|
+
export const Post = <T extends Object, K>(path = "/") => defaultDecorator<T, K>(path, "Post");
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
*
|
|
59
59
|
* @param path
|
|
60
60
|
* @returns
|
|
61
61
|
*/
|
|
62
|
-
export const Put = <T
|
|
62
|
+
export const Put = <T extends Object, K>(path = "/") => defaultDecorator<T, K>(path, "Put");
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
*
|
|
66
66
|
* @param path
|
|
67
67
|
* @returns
|
|
68
68
|
*/
|
|
69
|
-
export const Patch = <T
|
|
69
|
+
export const Patch = <T extends Object, K>(path = "/") => defaultDecorator<T, K>(path, "Patch");
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
*
|
|
73
73
|
* @param path
|
|
74
74
|
* @returns
|
|
75
75
|
*/
|
|
76
|
-
export const Delete = <T
|
|
76
|
+
export const Delete = <T extends Object, K>(path = "/") => defaultDecorator<T, K>(path, "Delete");
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
*
|
|
80
80
|
* @param path
|
|
81
81
|
* @returns
|
|
82
82
|
*/
|
|
83
|
-
export const Options = <T
|
|
83
|
+
export const Options = <T extends Object, K>(path = "/") => defaultDecorator<T, K>(path, "Options");
|
|
84
84
|
|
|
85
85
|
export default {
|
|
86
86
|
Get,
|
package/src/decorators/index.ts
CHANGED
|
@@ -29,9 +29,8 @@ export {
|
|
|
29
29
|
WebSocketServer
|
|
30
30
|
} from "./webSocketArguments";
|
|
31
31
|
export { WebSocketEvent } from "./webSocketEvent";
|
|
32
|
-
export { ZodSchema } from "./zodSchema";
|
|
33
32
|
|
|
34
|
-
export type { TArgumentsMetadata } from "./arguments";
|
|
33
|
+
export type { TArgumentsMetadata, TArgumentsMetadataCollection } from "./arguments";
|
|
35
34
|
export type { TContainerConfig, TContainerMetadata, TContainerOptions } from "./container";
|
|
36
35
|
export type { TControllerMetadata } from "./controller";
|
|
37
36
|
export type { TGuardMetadata } from "./guard";
|