@bool-ts/core 1.6.13 → 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 +501 -406
- 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 -806
- 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
package/.prettierrc
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"semi": true,
|
|
3
|
-
"tabWidth": 4,
|
|
4
|
-
"printWidth": 128,
|
|
5
|
-
"singleQuote": false,
|
|
6
|
-
"singleAttributePerLine": false,
|
|
7
|
-
"trailingComma": "none",
|
|
8
|
-
"bracketSameLine": true,
|
|
9
|
-
"bracketSpacing": true,
|
|
10
|
-
"htmlWhitespaceSensitivity": "ignore"
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"tabWidth": 4,
|
|
4
|
+
"printWidth": 128,
|
|
5
|
+
"singleQuote": false,
|
|
6
|
+
"singleAttributePerLine": false,
|
|
7
|
+
"trailingComma": "none",
|
|
8
|
+
"bracketSameLine": true,
|
|
9
|
+
"bracketSpacing": true,
|
|
10
|
+
"htmlWhitespaceSensitivity": "ignore"
|
|
11
|
+
}
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 BoolTS
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 BoolTS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/__test/controller.ts
CHANGED
|
@@ -1,79 +1,93 @@
|
|
|
1
|
-
import type { IService } from "./interfaces";
|
|
2
|
-
|
|
3
|
-
import * as Zod from "zod";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const
|
|
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
|
-
console.log("
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
import type { IService } from "./interfaces";
|
|
2
|
+
|
|
3
|
+
import * as Zod from "zod";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Controller,
|
|
7
|
+
Delete,
|
|
8
|
+
Get,
|
|
9
|
+
Inject,
|
|
10
|
+
Options,
|
|
11
|
+
Param,
|
|
12
|
+
Params,
|
|
13
|
+
Patch,
|
|
14
|
+
Post,
|
|
15
|
+
Put,
|
|
16
|
+
Query,
|
|
17
|
+
RequestBody,
|
|
18
|
+
RequestHeaders
|
|
19
|
+
} from "../src";
|
|
20
|
+
import { TestService } from "./service";
|
|
21
|
+
|
|
22
|
+
const postParamsSchema = Zod.object({
|
|
23
|
+
id: Zod.string(),
|
|
24
|
+
providerId: Zod.string().uuid()
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const bodySchema = Zod.object({
|
|
28
|
+
data: Zod.object({
|
|
29
|
+
name: Zod.string(),
|
|
30
|
+
age: Zod.number()
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const requestSchema = Zod.object({
|
|
35
|
+
headers: Zod.object({
|
|
36
|
+
authorization: Zod.string().min(10)
|
|
37
|
+
}),
|
|
38
|
+
body: bodySchema
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const stringSchema = Zod.object({}).refine(async (val) => {
|
|
42
|
+
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
43
|
+
await delay(10000);
|
|
44
|
+
|
|
45
|
+
return val;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const headersSchema = Zod.object({
|
|
49
|
+
"content-type": Zod.string()
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
@Controller("test")
|
|
53
|
+
export class TestController {
|
|
54
|
+
constructor(
|
|
55
|
+
@Inject(Symbol.for("etst")) private readonly testInject: any,
|
|
56
|
+
@Inject(TestService) private readonly testService: IService
|
|
57
|
+
) {
|
|
58
|
+
console.log("testInject", testInject);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Get("abc/:id")
|
|
62
|
+
public get(@Param("id") id: string) {
|
|
63
|
+
console.log("HEHE", id, typeof id);
|
|
64
|
+
console.log("this.testService", this.testService.exec());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Post("abc/:id/provider/:providerId")
|
|
68
|
+
public async post(
|
|
69
|
+
@RequestHeaders(headersSchema)
|
|
70
|
+
headers: Zod.infer<typeof headersSchema>,
|
|
71
|
+
@Params()
|
|
72
|
+
params: any,
|
|
73
|
+
@Query()
|
|
74
|
+
query: any,
|
|
75
|
+
@RequestBody(bodySchema)
|
|
76
|
+
body: Zod.infer<typeof bodySchema>
|
|
77
|
+
) {
|
|
78
|
+
console.log("req.headers", headers);
|
|
79
|
+
console.log("===========================");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Put()
|
|
83
|
+
public put(req: any) {}
|
|
84
|
+
|
|
85
|
+
@Patch("abc/:testId")
|
|
86
|
+
public patch(req: Request) {}
|
|
87
|
+
|
|
88
|
+
@Delete()
|
|
89
|
+
public delete(req: Request) {}
|
|
90
|
+
|
|
91
|
+
@Options()
|
|
92
|
+
public options(req: Request) {}
|
|
93
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IDispatcher } from "../src";
|
|
2
|
+
|
|
3
|
+
import { Dispatcher } from "../src";
|
|
4
|
+
|
|
5
|
+
@Dispatcher()
|
|
6
|
+
export class CustomDispatcher implements IDispatcher {
|
|
7
|
+
open() {
|
|
8
|
+
console.log("Dispatch -- Open");
|
|
9
|
+
console.log("===========================");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
close() {
|
|
13
|
+
console.log("Dispatch -- Close");
|
|
14
|
+
console.log("===========================");
|
|
15
|
+
}
|
|
16
|
+
}
|
package/__test/firstGuard.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Guard, IGuard } from "../src";
|
|
2
|
-
|
|
3
|
-
@Guard()
|
|
4
|
-
export class FirstGuard implements IGuard {
|
|
5
|
-
enforce(): boolean | Promise<boolean> {
|
|
6
|
-
console.log("Guard 01");
|
|
7
|
-
console.log("===========================");
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import { Guard, IGuard } from "../src";
|
|
2
|
+
|
|
3
|
+
@Guard()
|
|
4
|
+
export class FirstGuard implements IGuard {
|
|
5
|
+
enforce(): boolean | Promise<boolean> {
|
|
6
|
+
console.log("Guard 01");
|
|
7
|
+
console.log("===========================");
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
console.log("
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
import type { IMiddleware } from "../src";
|
|
2
|
+
import { Middleware } from "../src";
|
|
3
|
+
|
|
4
|
+
@Middleware()
|
|
5
|
+
export class FirstMiddleware implements IMiddleware {
|
|
6
|
+
start() {
|
|
7
|
+
console.log("Middleware 01 - Start");
|
|
8
|
+
console.log("===========================");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
end() {
|
|
12
|
+
console.log("Middleware 01 - End");
|
|
13
|
+
console.log("===========================");
|
|
14
|
+
}
|
|
15
|
+
}
|
package/__test/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
import { BoolFactory } from "../src";
|
|
4
|
-
import { TestModule } from "./module";
|
|
5
|
-
|
|
6
|
-
BoolFactory(TestModule, {
|
|
7
|
-
port: 3000
|
|
8
|
-
});
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
|
|
3
|
+
import { BoolFactory } from "../src";
|
|
4
|
+
import { TestModule } from "./module";
|
|
5
|
+
|
|
6
|
+
BoolFactory(TestModule, {
|
|
7
|
+
port: 3000
|
|
8
|
+
});
|
package/__test/interfaces.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export interface IRepository {
|
|
2
|
-
exec(): void;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export interface IService {
|
|
6
|
-
exec(): void;
|
|
7
|
-
}
|
|
1
|
+
export interface IRepository {
|
|
2
|
+
exec(): void;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface IService {
|
|
6
|
+
exec(): void;
|
|
7
|
+
}
|
package/__test/module.ts
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import { Module } from "../src";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { TestService } from "./service";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
export class TestModule {}
|
|
1
|
+
import { Module } from "../src";
|
|
2
|
+
import { TestController } from "./controller";
|
|
3
|
+
import { CustomDispatcher } from "./dispatcher";
|
|
4
|
+
import { FirstGuard } from "./firstGuard";
|
|
5
|
+
import { FirstMiddleware } from "./firstMiddleware";
|
|
6
|
+
import { TestRepository } from "./repository";
|
|
7
|
+
import { SecondGuard } from "./secondGuard";
|
|
8
|
+
import { SecondMiddleware } from "./secondMiddleware";
|
|
9
|
+
import { TestService } from "./service";
|
|
10
|
+
|
|
11
|
+
@Module<{
|
|
12
|
+
mongodb: string;
|
|
13
|
+
}>({
|
|
14
|
+
config: {
|
|
15
|
+
mongodb: "123"
|
|
16
|
+
},
|
|
17
|
+
loaders: {
|
|
18
|
+
mongodb: ({ config }) => {
|
|
19
|
+
return [Symbol.for("etst"), { hehe: "435345" }];
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
middlewares: [FirstMiddleware, SecondMiddleware],
|
|
23
|
+
guards: [FirstGuard, SecondGuard],
|
|
24
|
+
dispatchers: [CustomDispatcher],
|
|
25
|
+
controllers: [TestController],
|
|
26
|
+
dependencies: [TestService, TestRepository]
|
|
27
|
+
})
|
|
28
|
+
export class TestModule {}
|
package/__test/repository.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { IRepository } from "./interfaces";
|
|
2
|
-
|
|
3
|
-
import { Injectable } from "../src";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class TestRepository implements IRepository {
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
exec() {
|
|
12
|
-
console.log("This is test repository.");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default TestRepository;
|
|
1
|
+
import type { IRepository } from "./interfaces";
|
|
2
|
+
|
|
3
|
+
import { Injectable } from "../src";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class TestRepository implements IRepository {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
exec() {
|
|
12
|
+
console.log("This is test repository.");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default TestRepository;
|
package/__test/secondGuard.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Guard, IGuard } from "../src";
|
|
2
|
-
|
|
3
|
-
@Guard()
|
|
4
|
-
export class SecondGuard implements IGuard {
|
|
5
|
-
enforce(): boolean | Promise<boolean> {
|
|
6
|
-
console.log("Guard 02");
|
|
7
|
-
console.log("===========================");
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import { Guard, IGuard } from "../src";
|
|
2
|
+
|
|
3
|
+
@Guard()
|
|
4
|
+
export class SecondGuard implements IGuard {
|
|
5
|
+
enforce(): boolean | Promise<boolean> {
|
|
6
|
+
console.log("Guard 02");
|
|
7
|
+
console.log("===========================");
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
console.log("
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
import type { IMiddleware } from "../src";
|
|
2
|
+
import { Middleware } from "../src";
|
|
3
|
+
|
|
4
|
+
@Middleware()
|
|
5
|
+
export class SecondMiddleware implements IMiddleware {
|
|
6
|
+
start() {
|
|
7
|
+
console.log("Middleware 02 --- Start");
|
|
8
|
+
console.log("===========================");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
end() {
|
|
12
|
+
console.log("Middleware 02 --- End");
|
|
13
|
+
console.log("===========================");
|
|
14
|
+
}
|
|
15
|
+
}
|
package/__test/service.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type { IService, IRepository } from "./interfaces";
|
|
2
|
-
|
|
3
|
-
import { Inject, Injectable } from "../src";
|
|
4
|
-
import { TestRepository } from "./repository";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class TestService implements IService {
|
|
9
|
-
constructor(
|
|
10
|
-
@Inject(TestRepository) private readonly testRepository: IRepository
|
|
11
|
-
) { }
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
exec() {
|
|
17
|
-
console.log("This is test service.", this.testRepository);
|
|
18
|
-
this.testRepository.exec();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
import type { IService, IRepository } from "./interfaces";
|
|
2
|
+
|
|
3
|
+
import { Inject, Injectable } from "../src";
|
|
4
|
+
import { TestRepository } from "./repository";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class TestService implements IService {
|
|
9
|
+
constructor(
|
|
10
|
+
@Inject(TestRepository) private readonly testRepository: IRepository
|
|
11
|
+
) { }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
exec() {
|
|
17
|
+
console.log("This is test service.", this.testRepository);
|
|
18
|
+
this.testRepository.exec();
|
|
19
|
+
}
|
|
20
|
+
}
|
package/bun.lockb
CHANGED
|
Binary file
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Zod from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { contextArgsKey, paramArgsKey, paramsArgsKey, queryArgsKey, requestArgsKey, requestBodyArgsKey, requestHeaderArgsKey, requestHeadersArgsKey, responseHeadersArgsKey, routeModelArgsKey } from "../keys";
|
|
3
3
|
export type TArgumentsMetadata = {
|
|
4
4
|
index: number;
|
|
5
5
|
type: typeof requestHeadersArgsKey;
|
|
@@ -11,7 +11,7 @@ export type TArgumentsMetadata = {
|
|
|
11
11
|
zodSchema?: Zod.Schema;
|
|
12
12
|
} | {
|
|
13
13
|
index: number;
|
|
14
|
-
type: typeof
|
|
14
|
+
type: typeof requestBodyArgsKey;
|
|
15
15
|
zodSchema?: Zod.Schema;
|
|
16
16
|
parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text";
|
|
17
17
|
} | {
|
|
@@ -44,7 +44,7 @@ export type TArgumentsMetadata = {
|
|
|
44
44
|
};
|
|
45
45
|
export declare const RequestHeaders: (schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
46
46
|
export declare const RequestHeader: (key: string, schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
47
|
-
export declare const
|
|
47
|
+
export declare const RequestBody: (schema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
48
48
|
export declare const Params: (schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
49
49
|
export declare const Param: (key: string, schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
50
50
|
export declare const Query: (schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Zod from "zod";
|
|
2
|
-
import { argumentsKey,
|
|
2
|
+
import { argumentsKey, contextArgsKey, paramArgsKey, paramsArgsKey, queryArgsKey, requestArgsKey, requestBodyArgsKey, requestHeaderArgsKey, requestHeadersArgsKey, responseHeadersArgsKey, routeModelArgsKey } from "../keys";
|
|
3
3
|
export const RequestHeaders = (schema) => (target, methodName, parameterIndex) => {
|
|
4
4
|
if (!methodName) {
|
|
5
5
|
return;
|
|
@@ -25,14 +25,14 @@ export const RequestHeader = (key, schema) => (target, methodName, parameterInde
|
|
|
25
25
|
};
|
|
26
26
|
Reflect.defineMetadata(argumentsKey, requestHeaderMetadata, target.constructor, methodName);
|
|
27
27
|
};
|
|
28
|
-
export const
|
|
28
|
+
export const RequestBody = (schema, parser) => (target, methodName, parameterIndex) => {
|
|
29
29
|
if (!methodName) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
33
33
|
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
34
34
|
index: parameterIndex,
|
|
35
|
-
type:
|
|
35
|
+
type: requestBodyArgsKey,
|
|
36
36
|
zodSchema: schema,
|
|
37
37
|
parser: parser
|
|
38
38
|
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { dispatcherKey } from "../keys";
|
|
2
2
|
export const Dispatcher = () => (target) => {
|
|
3
|
-
if (!("execute" in target.prototype) || typeof target.prototype.execute !== "function") {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
3
|
const metadata = undefined;
|
|
7
4
|
Reflect.defineMetadata(dispatcherKey, metadata, target);
|
|
8
5
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Context, Param, Params, Query, Request, RequestBody, RequestHeader, RequestHeaders, ResponseHeaders, RouteModel } from "./arguments";
|
|
2
2
|
export { Controller } from "./controller";
|
|
3
3
|
export { Dispatcher } from "./dispatcher";
|
|
4
4
|
export { Guard } from "./guard";
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Context, Param, Params, Query, Request, RequestBody, RequestHeader, RequestHeaders, ResponseHeaders, RouteModel } from "./arguments";
|
|
2
2
|
export { Controller } from "./controller";
|
|
3
3
|
export { Dispatcher } from "./dispatcher";
|
|
4
4
|
export { Guard } from "./guard";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { middlewareKey } from "../keys";
|
|
2
2
|
export const Middleware = () => (target) => {
|
|
3
|
-
if (!("enforce" in target.prototype) || typeof target.prototype.enforce !== "function") {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
3
|
const metadata = undefined;
|
|
7
4
|
Reflect.defineMetadata(middlewareKey, metadata, target);
|
|
8
5
|
};
|
|
@@ -10,9 +10,8 @@ export type TModuleOptions<TConfig extends {} = {}> = Partial<{
|
|
|
10
10
|
loaders: TLoaders<TConfig>;
|
|
11
11
|
middlewares: TInstances;
|
|
12
12
|
guards: TInstances;
|
|
13
|
-
beforeDispatchers: TInstances;
|
|
14
13
|
controllers: TInstances;
|
|
15
|
-
|
|
14
|
+
dispatchers: TInstances;
|
|
16
15
|
}> | undefined;
|
|
17
16
|
export type TModuleMetadata<TConfig extends {} = {}> = Partial<{
|
|
18
17
|
config: TConfig | ((...args: any[]) => TConfig | Promise<TConfig>);
|
|
@@ -21,9 +20,8 @@ export type TModuleMetadata<TConfig extends {} = {}> = Partial<{
|
|
|
21
20
|
loaders: TLoaders<TConfig>;
|
|
22
21
|
middlewares: TInstances;
|
|
23
22
|
guards: TInstances;
|
|
24
|
-
beforeDispatchers: TInstances;
|
|
25
23
|
controllers: TInstances;
|
|
26
|
-
|
|
24
|
+
dispatchers: TInstances;
|
|
27
25
|
}> | undefined;
|
|
28
26
|
export declare const Module: <TConfig extends {} = {}>(args?: TModuleOptions<TConfig>) => <T extends {
|
|
29
27
|
new (...args: any[]): IModule;
|