@bool-ts/core 1.4.2 → 1.5.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/afterDispatcher.ts +9 -0
- package/__test/beforeDispatcher.ts +9 -0
- package/__test/controller.ts +66 -66
- package/__test/firstGuard.ts +10 -0
- package/__test/firstMiddleware.ts +9 -0
- package/__test/index.ts +8 -8
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +25 -16
- package/__test/repository.ts +16 -16
- package/__test/secondGuard.ts +10 -0
- package/__test/secondMiddleware.ts +9 -0
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/arguments.d.ts +12 -6
- package/dist/decorators/arguments.js +39 -26
- package/dist/decorators/controller.d.ts +9 -1
- package/dist/decorators/controller.js +6 -4
- package/dist/decorators/dispatcher.d.ts +7 -0
- package/dist/decorators/dispatcher.js +9 -0
- package/dist/decorators/guard.d.ts +7 -0
- package/dist/decorators/guard.js +9 -0
- package/dist/decorators/http.d.ts +4 -3
- package/dist/decorators/http.js +6 -5
- package/dist/decorators/index.d.ts +13 -3
- package/dist/decorators/index.js +5 -2
- package/dist/decorators/injectable.d.ts +1 -1
- package/dist/decorators/injectable.js +1 -4
- package/dist/decorators/middleware.d.ts +7 -0
- package/dist/decorators/middleware.js +9 -0
- package/dist/decorators/module.d.ts +28 -7
- package/dist/decorators/module.js +48 -1
- package/dist/entities/route.d.ts +5 -5
- package/dist/entities/routerGroup.d.ts +1 -1
- package/dist/hooks/factory.d.ts +3 -3
- package/dist/hooks/factory.js +282 -60
- package/dist/hooks/injector.js +6 -5
- package/dist/interfaces/index.d.ts +5 -2
- package/dist/interfaces/index.js +1 -1
- package/package.json +1 -1
- package/src/decorators/arguments.ts +214 -186
- package/src/decorators/controller.ts +22 -14
- package/src/decorators/dispatcher.ts +19 -0
- package/src/decorators/guard.ts +19 -0
- package/src/decorators/http.ts +81 -81
- package/src/decorators/index.ts +28 -7
- package/src/decorators/inject.ts +13 -13
- package/src/decorators/injectable.ts +8 -11
- package/src/decorators/middleware.ts +19 -0
- package/src/decorators/module.ts +100 -21
- package/src/decorators/zodSchema.ts +20 -20
- package/src/entities/index.ts +3 -3
- package/src/entities/route.ts +328 -328
- package/src/entities/router.ts +35 -35
- package/src/entities/routerGroup.ts +34 -34
- package/src/hooks/factory.ts +653 -332
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +43 -43
- package/src/http/clientError.ts +45 -45
- package/src/http/index.ts +63 -63
- package/src/http/serverError.ts +38 -38
- package/src/index.ts +6 -6
- package/src/interfaces/controller.d.ts +1 -0
- package/src/interfaces/dispatcher.d.ts +3 -0
- package/src/interfaces/guard.d.ts +3 -0
- package/src/interfaces/index.ts +5 -3
- package/src/interfaces/middleware.d.ts +3 -0
- package/src/interfaces/module.d.ts +1 -0
- package/test.http +31 -30
- package/tsconfig.json +107 -107
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,66 +1,66 @@
|
|
|
1
|
-
import type { IService } from "./interfaces";
|
|
2
|
-
|
|
3
|
-
import * as Zod from "zod";
|
|
4
|
-
|
|
5
|
-
import { Body, Controller, Delete, Get, Inject, Options, Params, Patch, Post, Put,
|
|
6
|
-
import { TestService } from "./service";
|
|
7
|
-
|
|
8
|
-
const postParamsSchema = Zod.object({
|
|
9
|
-
id: Zod.string(),
|
|
10
|
-
providerId: Zod.string().uuid()
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const bodySchema = Zod.object({
|
|
14
|
-
data: Zod.object({
|
|
15
|
-
name: Zod.string(),
|
|
16
|
-
age: Zod.number()
|
|
17
|
-
})
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const requestSchema = Zod.object({
|
|
21
|
-
headers: Zod.object({
|
|
22
|
-
authorization: Zod.string().min(10)
|
|
23
|
-
}),
|
|
24
|
-
body: bodySchema
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const stringSchema = Zod.object({}).refine(async (val) => {
|
|
28
|
-
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
-
await delay(10000);
|
|
30
|
-
|
|
31
|
-
return val;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
@Controller("test")
|
|
35
|
-
export class TestController {
|
|
36
|
-
constructor(@Inject(TestService) private readonly testService: IService) {}
|
|
37
|
-
|
|
38
|
-
@Get("abc")
|
|
39
|
-
public get(
|
|
40
|
-
console.log("HEHE");
|
|
41
|
-
console.log("this.testService", this.testService.exec());
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@Post("abc/:id/provider/:providerId")
|
|
45
|
-
public async post(
|
|
46
|
-
@Params(
|
|
47
|
-
params: any,
|
|
48
|
-
@Body(bodySchema)
|
|
49
|
-
|
|
50
|
-
) {
|
|
51
|
-
console.log("req.headers",
|
|
52
|
-
console.log("===========================");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@Put()
|
|
56
|
-
public put(req: any) {}
|
|
57
|
-
|
|
58
|
-
@Patch("abc/:testId")
|
|
59
|
-
public patch(req: Request) {}
|
|
60
|
-
|
|
61
|
-
@Delete()
|
|
62
|
-
public delete(req: Request) {}
|
|
63
|
-
|
|
64
|
-
@Options()
|
|
65
|
-
public options(req: Request) {}
|
|
66
|
-
}
|
|
1
|
+
import type { IService } from "./interfaces";
|
|
2
|
+
|
|
3
|
+
import * as Zod from "zod";
|
|
4
|
+
|
|
5
|
+
import { Body, Controller, Delete, Get, Inject, Options, Params, Patch, Post, Put, Param } from "../src";
|
|
6
|
+
import { TestService } from "./service";
|
|
7
|
+
|
|
8
|
+
const postParamsSchema = Zod.object({
|
|
9
|
+
id: Zod.string(),
|
|
10
|
+
providerId: Zod.string().uuid()
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const bodySchema = Zod.object({
|
|
14
|
+
data: Zod.object({
|
|
15
|
+
name: Zod.string(),
|
|
16
|
+
age: Zod.number()
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const requestSchema = Zod.object({
|
|
21
|
+
headers: Zod.object({
|
|
22
|
+
authorization: Zod.string().min(10)
|
|
23
|
+
}),
|
|
24
|
+
body: bodySchema
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const stringSchema = Zod.object({}).refine(async (val) => {
|
|
28
|
+
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
+
await delay(10000);
|
|
30
|
+
|
|
31
|
+
return val;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
@Controller("test")
|
|
35
|
+
export class TestController {
|
|
36
|
+
constructor(@Inject(TestService) private readonly testService: IService) {}
|
|
37
|
+
|
|
38
|
+
@Get("abc/:id")
|
|
39
|
+
public get(@Param("id") id: string) {
|
|
40
|
+
console.log("HEHE", id, typeof id);
|
|
41
|
+
console.log("this.testService", this.testService.exec());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Post("abc/:id/provider/:providerId")
|
|
45
|
+
public async post(
|
|
46
|
+
@Params()
|
|
47
|
+
params: any,
|
|
48
|
+
@Body(bodySchema)
|
|
49
|
+
body: Zod.infer<typeof bodySchema>
|
|
50
|
+
) {
|
|
51
|
+
console.log("req.headers", body, params);
|
|
52
|
+
console.log("===========================");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Put()
|
|
56
|
+
public put(req: any) {}
|
|
57
|
+
|
|
58
|
+
@Patch("abc/:testId")
|
|
59
|
+
public patch(req: Request) {}
|
|
60
|
+
|
|
61
|
+
@Delete()
|
|
62
|
+
public delete(req: Request) {}
|
|
63
|
+
|
|
64
|
+
@Options()
|
|
65
|
+
public options(req: Request) {}
|
|
66
|
+
}
|
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,16 +1,25 @@
|
|
|
1
|
-
import { Module } from "../src";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { Module } from "../src";
|
|
2
|
+
import { AfterDispatcher } from "./afterDispatcher";
|
|
3
|
+
import { BeforeDispatcher } from "./beforeDispatcher";
|
|
4
|
+
import { TestController } from "./controller";
|
|
5
|
+
import { FirstGuard } from "./firstGuard";
|
|
6
|
+
import { FirstMiddleware } from "./firstMiddleware";
|
|
7
|
+
import { SecondMiddleware } from "./secondMiddleware";
|
|
8
|
+
import { TestRepository } from "./repository";
|
|
9
|
+
import { TestService } from "./service";
|
|
10
|
+
import { SecondGuard } from "./secondGuard";
|
|
11
|
+
|
|
12
|
+
@Module({
|
|
13
|
+
options: {
|
|
14
|
+
allowOrigins: ["*"]
|
|
15
|
+
},
|
|
16
|
+
middlewares: [FirstMiddleware, SecondMiddleware],
|
|
17
|
+
guards: [FirstGuard, SecondGuard],
|
|
18
|
+
beforeDispatchers: [BeforeDispatcher],
|
|
19
|
+
afterDispatchers: [AfterDispatcher],
|
|
20
|
+
controllers: [TestController],
|
|
21
|
+
dependencies: [TestService, TestRepository]
|
|
22
|
+
})
|
|
23
|
+
export class TestModule {}
|
|
24
|
+
|
|
25
|
+
export default 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/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
|
File without changes
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import * as Zod from "zod";
|
|
2
2
|
export declare enum EArgumentTypes {
|
|
3
|
-
|
|
3
|
+
requestHeaders = "REQUEST_HEADERS",
|
|
4
4
|
body = "BODY",
|
|
5
5
|
params = "PARAMS",
|
|
6
6
|
param = "PARAM",
|
|
7
7
|
query = "QUERY",
|
|
8
|
-
request = "REQUEST"
|
|
8
|
+
request = "REQUEST",
|
|
9
|
+
responseHeaders = "RESPONSE_HEADERS"
|
|
9
10
|
}
|
|
10
|
-
export type
|
|
11
|
+
export type TArgumentsMetadata = {
|
|
11
12
|
index: number;
|
|
12
|
-
type: EArgumentTypes.
|
|
13
|
+
type: EArgumentTypes.requestHeaders;
|
|
13
14
|
zodSchema?: Zod.Schema;
|
|
14
15
|
} | {
|
|
15
16
|
index: number;
|
|
@@ -33,11 +34,16 @@ export type TMetadata = {
|
|
|
33
34
|
index: number;
|
|
34
35
|
type: EArgumentTypes.request;
|
|
35
36
|
zodSchema?: Zod.Schema;
|
|
37
|
+
} | {
|
|
38
|
+
index: number;
|
|
39
|
+
type: EArgumentTypes.responseHeaders;
|
|
40
|
+
zodSchema?: Zod.Schema;
|
|
36
41
|
};
|
|
37
|
-
export declare const
|
|
38
|
-
export declare const
|
|
42
|
+
export declare const argumentsKey: unique symbol;
|
|
43
|
+
export declare const RequestHeaders: (zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
39
44
|
export declare const Body: (zodSchema?: Zod.Schema, parser?: "arrayBuffer" | "blob" | "formData" | "json" | "text") => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
40
45
|
export declare const Params: (zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
41
46
|
export declare const Param: (key: string, zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
42
47
|
export declare const Query: (zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
43
48
|
export declare const Request: (zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
49
|
+
export declare const ResponseHeaders: (zodSchema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import * as Zod from "zod";
|
|
2
2
|
export var EArgumentTypes;
|
|
3
3
|
(function (EArgumentTypes) {
|
|
4
|
-
EArgumentTypes["
|
|
4
|
+
EArgumentTypes["requestHeaders"] = "REQUEST_HEADERS";
|
|
5
5
|
EArgumentTypes["body"] = "BODY";
|
|
6
6
|
EArgumentTypes["params"] = "PARAMS";
|
|
7
7
|
EArgumentTypes["param"] = "PARAM";
|
|
8
8
|
EArgumentTypes["query"] = "QUERY";
|
|
9
9
|
EArgumentTypes["request"] = "REQUEST";
|
|
10
|
+
EArgumentTypes["responseHeaders"] = "RESPONSE_HEADERS";
|
|
10
11
|
})(EArgumentTypes || (EArgumentTypes = {}));
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
12
|
+
export const argumentsKey = Symbol.for("__bool:arguments__");
|
|
13
|
+
export const RequestHeaders = (zodSchema) => {
|
|
13
14
|
return (target, methodName, parameterIndex) => {
|
|
14
15
|
if (!methodName) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
|
-
const headersMetadata = Reflect.getOwnMetadata(
|
|
18
|
+
const headersMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
18
19
|
headersMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
19
20
|
index: parameterIndex,
|
|
20
|
-
type: EArgumentTypes.
|
|
21
|
+
type: EArgumentTypes.requestHeaders,
|
|
21
22
|
zodSchema: zodSchema
|
|
22
23
|
};
|
|
23
|
-
Reflect.defineMetadata(
|
|
24
|
+
Reflect.defineMetadata(argumentsKey, headersMetadata, target.constructor, methodName);
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
export const Body = (zodSchema, parser) => {
|
|
@@ -28,43 +29,41 @@ export const Body = (zodSchema, parser) => {
|
|
|
28
29
|
if (!methodName) {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
|
-
const bodyMetadata = Reflect.getOwnMetadata(
|
|
32
|
+
const bodyMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
32
33
|
bodyMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
33
34
|
index: parameterIndex,
|
|
34
35
|
type: EArgumentTypes.body,
|
|
35
36
|
zodSchema: zodSchema,
|
|
36
37
|
parser: parser
|
|
37
38
|
};
|
|
38
|
-
Reflect.defineMetadata(
|
|
39
|
+
Reflect.defineMetadata(argumentsKey, bodyMetadata, target.constructor, methodName);
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
|
-
export const Params = (zodSchema) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
zodSchema: zodSchema
|
|
51
|
-
};
|
|
52
|
-
Reflect.defineMetadata(controllerActionArgumentsKey, paramsMetadata, target.constructor, methodName);
|
|
42
|
+
export const Params = (zodSchema) => (target, methodName, parameterIndex) => {
|
|
43
|
+
if (!methodName) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
47
|
+
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
48
|
+
index: parameterIndex,
|
|
49
|
+
type: EArgumentTypes.params,
|
|
50
|
+
zodSchema: zodSchema
|
|
53
51
|
};
|
|
52
|
+
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
54
53
|
};
|
|
55
54
|
export const Param = (key, zodSchema) => {
|
|
56
55
|
return (target, methodName, parameterIndex) => {
|
|
57
56
|
if (!methodName) {
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
|
-
const paramsMetadata = Reflect.getOwnMetadata(
|
|
59
|
+
const paramsMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
61
60
|
paramsMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
62
61
|
index: parameterIndex,
|
|
63
62
|
type: EArgumentTypes.param,
|
|
64
63
|
key: key,
|
|
65
64
|
zodSchema: zodSchema
|
|
66
65
|
};
|
|
67
|
-
Reflect.defineMetadata(
|
|
66
|
+
Reflect.defineMetadata(argumentsKey, paramsMetadata, target.constructor, methodName);
|
|
68
67
|
};
|
|
69
68
|
};
|
|
70
69
|
export const Query = (zodSchema) => {
|
|
@@ -72,13 +71,13 @@ export const Query = (zodSchema) => {
|
|
|
72
71
|
if (!methodName) {
|
|
73
72
|
return;
|
|
74
73
|
}
|
|
75
|
-
const queryMetadata = Reflect.getOwnMetadata(
|
|
74
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
76
75
|
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
77
76
|
index: parameterIndex,
|
|
78
77
|
type: EArgumentTypes.params,
|
|
79
78
|
zodSchema: zodSchema
|
|
80
79
|
};
|
|
81
|
-
Reflect.defineMetadata(
|
|
80
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
82
81
|
};
|
|
83
82
|
};
|
|
84
83
|
export const Request = (zodSchema) => {
|
|
@@ -86,12 +85,26 @@ export const Request = (zodSchema) => {
|
|
|
86
85
|
if (!methodName) {
|
|
87
86
|
return;
|
|
88
87
|
}
|
|
89
|
-
const queryMetadata = Reflect.getOwnMetadata(
|
|
88
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
90
89
|
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
91
90
|
index: parameterIndex,
|
|
92
91
|
type: EArgumentTypes.request,
|
|
93
92
|
zodSchema: zodSchema
|
|
94
93
|
};
|
|
95
|
-
Reflect.defineMetadata(
|
|
94
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export const ResponseHeaders = (zodSchema) => {
|
|
98
|
+
return (target, methodName, parameterIndex) => {
|
|
99
|
+
if (!methodName) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const queryMetadata = Reflect.getOwnMetadata(argumentsKey, target.constructor, methodName) || {};
|
|
103
|
+
queryMetadata[`argumentIndexes.${parameterIndex}`] = {
|
|
104
|
+
index: parameterIndex,
|
|
105
|
+
type: EArgumentTypes.responseHeaders,
|
|
106
|
+
zodSchema: zodSchema
|
|
107
|
+
};
|
|
108
|
+
Reflect.defineMetadata(argumentsKey, queryMetadata, target.constructor, methodName);
|
|
96
109
|
};
|
|
97
110
|
};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import type { IController } from "../interfaces/controller";
|
|
2
|
+
import { type THttpMetadata } from "./http";
|
|
3
|
+
export type TControllerMetadata = Required<{
|
|
4
|
+
prefix: string;
|
|
5
|
+
httpMetadata: THttpMetadata;
|
|
6
|
+
}>;
|
|
1
7
|
export declare const controllerKey: unique symbol;
|
|
2
|
-
export declare const Controller: (prefix: string) => <T extends
|
|
8
|
+
export declare const Controller: (prefix: string) => <T extends {
|
|
9
|
+
new (...args: any[]): IController;
|
|
10
|
+
}>(target: T) => void;
|
|
3
11
|
export default Controller;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { controllerHttpKey } from "./http";
|
|
2
2
|
export const controllerKey = Symbol.for("__bool:controller__");
|
|
3
3
|
export const Controller = (prefix) => (target) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const metadata = {
|
|
5
|
+
prefix: !prefix.startsWith("/") ? `/${prefix}` : prefix,
|
|
6
|
+
httpMetadata: [...(Reflect.getOwnMetadata(controllerHttpKey, target.constructor) || [])]
|
|
7
|
+
};
|
|
8
|
+
Reflect.defineMetadata(controllerKey, metadata, target);
|
|
7
9
|
};
|
|
8
10
|
export default Controller;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IDispatcher } from "../interfaces/dispatcher";
|
|
2
|
+
export type TDispatcherMetadata = undefined;
|
|
3
|
+
export declare const dispatcherKey: unique symbol;
|
|
4
|
+
export declare const Dispatcher: () => <T extends {
|
|
5
|
+
new (...args: any[]): IDispatcher;
|
|
6
|
+
}>(target: T) => void;
|
|
7
|
+
export default Dispatcher;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const dispatcherKey = Symbol.for("__bool:dispatcher__");
|
|
2
|
+
export const Dispatcher = () => (target) => {
|
|
3
|
+
if (!("execute" in target.prototype) || typeof target.prototype.execute !== "function") {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const metadata = undefined;
|
|
7
|
+
Reflect.defineMetadata(dispatcherKey, metadata, target);
|
|
8
|
+
};
|
|
9
|
+
export default Dispatcher;
|