@bool-ts/core 1.3.2 → 1.4.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 -0
- package/LICENSE +21 -21
- package/__test/controller.ts +66 -79
- package/__test/index.ts +8 -11
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +16 -17
- package/__test/repository.ts +16 -16
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/arguments.d.ts +31 -0
- package/dist/decorators/arguments.js +67 -0
- package/dist/decorators/controller.d.ts +2 -2
- package/dist/decorators/controller.js +6 -10
- package/dist/decorators/http.d.ts +1 -1
- package/dist/decorators/http.js +16 -103
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +7 -26
- package/dist/decorators/inject.js +5 -9
- package/dist/decorators/injectable.d.ts +2 -2
- package/dist/decorators/injectable.js +4 -8
- package/dist/decorators/module.d.ts +4 -2
- package/dist/decorators/module.js +4 -8
- package/dist/decorators/zodSchema.d.ts +1 -1
- package/dist/decorators/zodSchema.js +5 -8
- package/dist/entities/index.d.ts +3 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/route.d.ts +101 -0
- package/dist/entities/route.js +257 -0
- package/dist/entities/router.d.ts +10 -0
- package/dist/entities/router.js +25 -0
- package/dist/entities/routerGroup.d.ts +14 -0
- package/dist/entities/routerGroup.js +24 -0
- package/dist/hooks/factory.d.ts +12 -12
- package/dist/hooks/factory.js +180 -151
- package/dist/hooks/index.js +2 -7
- package/dist/hooks/injector.js +7 -10
- package/dist/http/clientError.d.ts +1 -1
- package/dist/http/clientError.js +3 -7
- package/dist/http/index.d.ts +12 -2
- package/dist/http/index.js +34 -73
- package/dist/http/serverError.js +3 -7
- package/dist/index.js +5 -21
- package/dist/interfaces/index.js +1 -3
- package/dist/ultils/asyncFunction.js +1 -4
- package/dist/ultils/index.js +1 -17
- package/package.json +30 -33
- package/src/decorators/arguments.ts +128 -0
- package/src/decorators/controller.ts +14 -18
- package/src/decorators/http.ts +81 -195
- package/src/decorators/index.ts +7 -6
- package/src/decorators/inject.ts +13 -19
- package/src/decorators/injectable.ts +11 -12
- package/src/decorators/module.ts +21 -22
- package/src/decorators/zodSchema.ts +20 -27
- package/src/entities/index.ts +3 -0
- package/src/entities/route.ts +328 -0
- package/src/entities/router.ts +35 -0
- package/src/entities/routerGroup.ts +34 -0
- package/src/hooks/factory.ts +285 -205
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +43 -43
- package/src/http/clientError.ts +45 -56
- package/src/http/index.ts +63 -72
- package/src/http/serverError.ts +38 -38
- package/src/index.ts +6 -6
- package/src/interfaces/index.ts +3 -3
- package/test.http +30 -28
- package/tsconfig.json +107 -109
package/dist/ultils/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./asyncFunction"), exports);
|
|
1
|
+
export * from "./asyncFunction";
|
package/package.json
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"typescript": "^5.4.5"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
2
|
+
"name": "@bool-ts/core",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "bun --hot run __test/index.ts",
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/BoolTS/core.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "Trần Đức Tâm (Neo)",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/BoolTS/core/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/BoolTS/core#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"colors": "^1.4.0",
|
|
22
|
+
"qs": "^6.13.0",
|
|
23
|
+
"reflect-metadata": "^0.2.2",
|
|
24
|
+
"zod": "^3.23.8"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/bun": "^1.1.6",
|
|
28
|
+
"@types/qs": "^6.9.15",
|
|
29
|
+
"typescript": "^5.5.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as Zod from "zod";
|
|
2
|
+
|
|
3
|
+
export enum EArgumentTypes {
|
|
4
|
+
headers = "HEADERS",
|
|
5
|
+
body = "BODY",
|
|
6
|
+
params = "PARAMS",
|
|
7
|
+
query = "QUERY"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type TMetadata =
|
|
11
|
+
| {
|
|
12
|
+
index: number;
|
|
13
|
+
type: EArgumentTypes.headers;
|
|
14
|
+
zodSchema?: Zod.Schema;
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
index: number;
|
|
18
|
+
type: EArgumentTypes.body;
|
|
19
|
+
zodSchema?: Zod.Schema;
|
|
20
|
+
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
index: number;
|
|
24
|
+
type: EArgumentTypes.params;
|
|
25
|
+
key?: string;
|
|
26
|
+
zodSchema?: Zod.Schema;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
index: number;
|
|
30
|
+
type: EArgumentTypes.query;
|
|
31
|
+
zodSchema?: Zod.Schema;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const controllerActionArgumentsKey = Symbol.for("__bool:controller.action::arguments__");
|
|
35
|
+
|
|
36
|
+
export const Headers = (zodSchema?: Zod.Schema) => {
|
|
37
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
38
|
+
if (!methodName) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const headersMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
|
|
43
|
+
|
|
44
|
+
headersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
45
|
+
index: parameterIndex,
|
|
46
|
+
type: EArgumentTypes.headers,
|
|
47
|
+
zodSchema: zodSchema
|
|
48
|
+
} satisfies Extract<
|
|
49
|
+
TMetadata,
|
|
50
|
+
{
|
|
51
|
+
type: EArgumentTypes.headers;
|
|
52
|
+
}
|
|
53
|
+
>;
|
|
54
|
+
|
|
55
|
+
Reflect.defineMetadata(controllerActionArgumentsKey, headersMetadata, target.constructor, methodName);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const Body = (zodSchema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") => {
|
|
60
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
61
|
+
if (!methodName) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const bodyMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
|
|
66
|
+
|
|
67
|
+
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
68
|
+
index: parameterIndex,
|
|
69
|
+
type: EArgumentTypes.body,
|
|
70
|
+
zodSchema: zodSchema,
|
|
71
|
+
parser: parser
|
|
72
|
+
} satisfies Extract<
|
|
73
|
+
TMetadata,
|
|
74
|
+
{
|
|
75
|
+
type: EArgumentTypes.body;
|
|
76
|
+
}
|
|
77
|
+
>;
|
|
78
|
+
|
|
79
|
+
Reflect.defineMetadata(controllerActionArgumentsKey, bodyMetadata, target.constructor, methodName);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const Params = (key?: string, zodSchema?: Zod.Schema) => {
|
|
84
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
85
|
+
if (!methodName) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const paramsMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
|
|
90
|
+
|
|
91
|
+
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
92
|
+
index: parameterIndex,
|
|
93
|
+
type: EArgumentTypes.params,
|
|
94
|
+
key: key,
|
|
95
|
+
zodSchema: zodSchema
|
|
96
|
+
} satisfies Extract<
|
|
97
|
+
TMetadata,
|
|
98
|
+
{
|
|
99
|
+
type: EArgumentTypes.params;
|
|
100
|
+
}
|
|
101
|
+
>;
|
|
102
|
+
|
|
103
|
+
Reflect.defineMetadata(controllerActionArgumentsKey, paramsMetadata, target.constructor, methodName);
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const Query = (zodSchema?: Zod.Schema) => {
|
|
108
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
109
|
+
if (!methodName) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const queryMetadata = Reflect.getOwnMetadata(controllerActionArgumentsKey, target.constructor, methodName) || {};
|
|
114
|
+
|
|
115
|
+
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
116
|
+
index: parameterIndex,
|
|
117
|
+
type: EArgumentTypes.params,
|
|
118
|
+
zodSchema: zodSchema
|
|
119
|
+
} satisfies Extract<
|
|
120
|
+
TMetadata,
|
|
121
|
+
{
|
|
122
|
+
type: EArgumentTypes.params;
|
|
123
|
+
}
|
|
124
|
+
>;
|
|
125
|
+
|
|
126
|
+
Reflect.defineMetadata(controllerActionArgumentsKey, queryMetadata, target.constructor, methodName);
|
|
127
|
+
};
|
|
128
|
+
};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { injectableKey } from "./injectable";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return target;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default Controller;
|
|
1
|
+
import { injectableKey } from "./injectable";
|
|
2
|
+
|
|
3
|
+
export const controllerKey = Symbol.for("__bool:controller__");
|
|
4
|
+
|
|
5
|
+
export const Controller =
|
|
6
|
+
(prefix: string) =>
|
|
7
|
+
<T extends Object>(target: T) => {
|
|
8
|
+
Reflect.defineMetadata(controllerKey, !prefix.startsWith("/") ? `/${prefix}` : prefix, target);
|
|
9
|
+
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
10
|
+
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default Controller;
|
package/src/decorators/http.ts
CHANGED
|
@@ -1,195 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return currentMethod.apply(this, arguments);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
descriptor.value = async function () {
|
|
87
|
-
const zodSchemaMetadata = Reflect.getOwnMetadata(controllerRouteZodSchemaKey, target.constructor, methodName);
|
|
88
|
-
|
|
89
|
-
if (zodSchemaMetadata) {
|
|
90
|
-
for (const zodSchemaProp in zodSchemaMetadata) {
|
|
91
|
-
const tmpZodMetadata = zodSchemaMetadata[zodSchemaProp];
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const validation = await tmpZodMetadata.schema.safeParseAsync(arguments[tmpZodMetadata.index]);
|
|
95
|
-
|
|
96
|
-
if (!validation.success) {
|
|
97
|
-
throw new HttpClientError({
|
|
98
|
-
httpCode: 400,
|
|
99
|
-
message: `Validation at the [${methodName}] method fails at positional argument [${tmpZodMetadata.index}].`,
|
|
100
|
-
data: validation.error.issues
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
arguments[tmpZodMetadata.index] = validation.data;
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
if (error instanceof HttpClientError) {
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
throw new HttpServerError({
|
|
112
|
-
httpCode: 500,
|
|
113
|
-
message: `Validation at the [${methodName}] method error at positional argument [${tmpZodMetadata.index}].`,
|
|
114
|
-
data: !(error instanceof Error) ? error : [{
|
|
115
|
-
message: error.message,
|
|
116
|
-
code: error.name,
|
|
117
|
-
cause: error.cause
|
|
118
|
-
}]
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return currentMethod.apply(this, arguments);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
* @param path
|
|
132
|
-
* @returns
|
|
133
|
-
*/
|
|
134
|
-
export const Get = (
|
|
135
|
-
path = "/"
|
|
136
|
-
) => defaultDecorator(path, "Get");
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
*
|
|
141
|
-
* @param path
|
|
142
|
-
* @returns
|
|
143
|
-
*/
|
|
144
|
-
export const Post = (
|
|
145
|
-
path = "/"
|
|
146
|
-
) => defaultDecorator(path, "Post");
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
*
|
|
151
|
-
* @param path
|
|
152
|
-
* @returns
|
|
153
|
-
*/
|
|
154
|
-
export const Put = (
|
|
155
|
-
path = "/"
|
|
156
|
-
) => defaultDecorator(path, "Put");
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
*
|
|
161
|
-
* @param path
|
|
162
|
-
* @returns
|
|
163
|
-
*/
|
|
164
|
-
export const Patch = (
|
|
165
|
-
path = "/"
|
|
166
|
-
) => defaultDecorator(path, "Patch");
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
*
|
|
171
|
-
* @param path
|
|
172
|
-
* @returns
|
|
173
|
-
*/
|
|
174
|
-
export const Delete = (
|
|
175
|
-
path = "/"
|
|
176
|
-
) => defaultDecorator(path, "Delete");
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
*
|
|
181
|
-
* @param path
|
|
182
|
-
* @returns
|
|
183
|
-
*/
|
|
184
|
-
export const Options = (
|
|
185
|
-
path = "/"
|
|
186
|
-
) => defaultDecorator(path, "Options");
|
|
187
|
-
|
|
188
|
-
export default {
|
|
189
|
-
Get,
|
|
190
|
-
Post,
|
|
191
|
-
Put,
|
|
192
|
-
Patch,
|
|
193
|
-
Delete
|
|
194
|
-
};
|
|
195
|
-
|
|
1
|
+
export interface IControllerRoute {
|
|
2
|
+
path: string;
|
|
3
|
+
httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
4
|
+
methodName: string;
|
|
5
|
+
descriptor: PropertyDescriptor;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const controllerRoutesKey = Symbol.for("__bool:controller.routes__");
|
|
9
|
+
|
|
10
|
+
const defaultDecorator =
|
|
11
|
+
(path: string, method: "Get" | "Post" | "Put" | "Patch" | "Delete" | "Options") =>
|
|
12
|
+
(target: Object, methodName: string, descriptor: PropertyDescriptor) => {
|
|
13
|
+
if (!(descriptor.value instanceof Function)) {
|
|
14
|
+
throw Error(`${method} decorator only use for class method.`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Define controller metadata
|
|
18
|
+
Reflect.defineMetadata(
|
|
19
|
+
controllerRoutesKey,
|
|
20
|
+
[
|
|
21
|
+
...(Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || []),
|
|
22
|
+
{
|
|
23
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
24
|
+
httpMethod: method.toUpperCase(),
|
|
25
|
+
methodName: methodName,
|
|
26
|
+
descriptor: descriptor
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
target.constructor
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param path
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export const Get = (path = "/") => defaultDecorator(path, "Get");
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param path
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export const Post = (path = "/") => defaultDecorator(path, "Post");
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param path
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export const Put = (path = "/") => defaultDecorator(path, "Put");
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param path
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export const Patch = (path = "/") => defaultDecorator(path, "Patch");
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param path
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export const Delete = (path = "/") => defaultDecorator(path, "Delete");
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param path
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export const Options = (path = "/") => defaultDecorator(path, "Options");
|
|
74
|
+
|
|
75
|
+
export default {
|
|
76
|
+
Get,
|
|
77
|
+
Post,
|
|
78
|
+
Put,
|
|
79
|
+
Patch,
|
|
80
|
+
Delete
|
|
81
|
+
};
|
package/src/decorators/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
1
|
+
export { Headers, Body, Params, Query, EArgumentTypes } from "./arguments";
|
|
2
|
+
export { Controller, controllerKey } from "./controller";
|
|
3
|
+
export { Inject, injectKey } from "./inject";
|
|
4
|
+
export { Injectable, injectableKey } from "./injectable";
|
|
5
|
+
export { Module, moduleKey, type TModuleOptions } from "./module";
|
|
6
|
+
export { Get, Post, Put, Patch, Delete, Options, controllerRoutesKey, type IControllerRoute } from "./http";
|
|
7
|
+
export { ZodSchema, controllerRouteZodSchemaKey } from "./zodSchema";
|
package/src/decorators/inject.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
export const injectKey = "design:paramtypes";
|
|
2
|
-
|
|
3
|
-
export const Inject = <T extends Object>(
|
|
4
|
-
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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>(classDefinition: { new (...args: any[]): T }) => {
|
|
4
|
+
return (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => {
|
|
5
|
+
const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target) || [];
|
|
6
|
+
|
|
7
|
+
designParameterTypes[parameterIndex] = classDefinition;
|
|
8
|
+
|
|
9
|
+
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default Inject;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export const injectableKey = "__bool:injectable__";
|
|
2
|
-
|
|
3
|
-
export const Injectable =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export default Injectable;
|
|
1
|
+
export const injectableKey = Symbol.for("__bool:injectable__");
|
|
2
|
+
|
|
3
|
+
export const Injectable =
|
|
4
|
+
() =>
|
|
5
|
+
<T extends Object>(target: T) => {
|
|
6
|
+
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
7
|
+
|
|
8
|
+
return target;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default Injectable;
|
package/src/decorators/module.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
export type TModuleOptions =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export default Module;
|
|
1
|
+
export type TModuleOptions =
|
|
2
|
+
| Partial<{
|
|
3
|
+
prefix: string;
|
|
4
|
+
controllers: Array<new (...args: any[]) => unknown>;
|
|
5
|
+
dependencies: Array<new (...args: any[]) => unknown>;
|
|
6
|
+
allowOrigins: string | Array<string>;
|
|
7
|
+
allowMethods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
|
|
8
|
+
}>
|
|
9
|
+
| undefined;
|
|
10
|
+
|
|
11
|
+
export const moduleKey = Symbol.for("__bool:module__");
|
|
12
|
+
|
|
13
|
+
export const Module =
|
|
14
|
+
(args?: TModuleOptions) =>
|
|
15
|
+
<T extends { new (...args: any[]): {} }>(target: T) => {
|
|
16
|
+
Reflect.defineMetadata(moduleKey, args, target);
|
|
17
|
+
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default Module;
|