@bool-ts/core 1.1.1 → 1.1.2
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/LICENSE +21 -21
- package/__test/controller.ts +63 -63
- package/__test/index.ts +11 -11
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +17 -17
- package/__test/repository.ts +16 -16
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/controller.js +10 -6
- package/dist/decorators/http.js +34 -25
- package/dist/decorators/index.js +23 -5
- package/dist/decorators/inject.js +9 -5
- package/dist/decorators/injectable.js +8 -4
- package/dist/decorators/module.js +8 -4
- package/dist/hooks/factory.js +48 -21
- package/dist/hooks/index.js +7 -2
- package/dist/hooks/injector.js +10 -7
- package/dist/http/clientError.js +7 -3
- package/dist/http/index.js +25 -7
- package/dist/http/serverError.js +7 -3
- package/dist/index.js +21 -5
- package/dist/interfaces/index.js +3 -1
- package/package.json +1 -1
- package/src/decorators/controller.ts +18 -18
- package/src/decorators/http.ts +185 -185
- package/src/decorators/index.ts +5 -5
- package/src/decorators/inject.ts +19 -19
- package/src/decorators/injectable.ts +12 -12
- package/src/decorators/module.ts +21 -21
- package/src/hooks/factory.ts +193 -193
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +43 -43
- package/src/http/clientError.ts +57 -57
- package/src/http/index.ts +68 -68
- package/src/http/serverError.ts +39 -39
- package/src/index.ts +6 -6
- package/src/interfaces/index.ts +3 -3
- package/test.http +28 -28
- package/tsconfig.json +108 -108
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,63 +1,63 @@
|
|
|
1
|
-
import type { IService } from "./interfaces";
|
|
2
|
-
|
|
3
|
-
import { Controller, Delete, Get, Inject, Options, Patch, Post, Put } from "../src";
|
|
4
|
-
import { TestService } from "./service";
|
|
5
|
-
import { Request, Response } from "express";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@Controller("test")
|
|
9
|
-
export class TestController {
|
|
10
|
-
constructor(
|
|
11
|
-
@Inject(TestService) private readonly testService: IService
|
|
12
|
-
) { }
|
|
13
|
-
|
|
14
|
-
@Get()
|
|
15
|
-
private _get(
|
|
16
|
-
req: Request,
|
|
17
|
-
res: Response
|
|
18
|
-
) {
|
|
19
|
-
console.log("this.testService", this.testService.exec())
|
|
20
|
-
res.json({ test: "success" }).send();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Post()
|
|
24
|
-
private _post(
|
|
25
|
-
req: Request,
|
|
26
|
-
res: Response
|
|
27
|
-
) {
|
|
28
|
-
console.log("req.body", req.body);
|
|
29
|
-
res.json({ test: "success" }).send();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@Put()
|
|
33
|
-
private _put(
|
|
34
|
-
req: Request,
|
|
35
|
-
res: Response
|
|
36
|
-
) {
|
|
37
|
-
res.json({ test: "success" }).send();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Patch()
|
|
41
|
-
private _patch(
|
|
42
|
-
req: Request,
|
|
43
|
-
res: Response
|
|
44
|
-
) {
|
|
45
|
-
res.json({ test: "success" }).send();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Delete()
|
|
49
|
-
private _delete(
|
|
50
|
-
req: Request,
|
|
51
|
-
res: Response
|
|
52
|
-
) {
|
|
53
|
-
res.json({ test: "success" }).send();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@Options()
|
|
57
|
-
private _options(
|
|
58
|
-
req: Request,
|
|
59
|
-
res: Response
|
|
60
|
-
) {
|
|
61
|
-
res.json({ test: "success" }).send();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import type { IService } from "./interfaces";
|
|
2
|
+
|
|
3
|
+
import { Controller, Delete, Get, Inject, Options, Patch, Post, Put } from "../src";
|
|
4
|
+
import { TestService } from "./service";
|
|
5
|
+
import { Request, Response } from "express";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@Controller("test")
|
|
9
|
+
export class TestController {
|
|
10
|
+
constructor(
|
|
11
|
+
@Inject(TestService) private readonly testService: IService
|
|
12
|
+
) { }
|
|
13
|
+
|
|
14
|
+
@Get()
|
|
15
|
+
private _get(
|
|
16
|
+
req: Request,
|
|
17
|
+
res: Response
|
|
18
|
+
) {
|
|
19
|
+
console.log("this.testService", this.testService.exec())
|
|
20
|
+
res.json({ test: "success" }).send();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Post()
|
|
24
|
+
private _post(
|
|
25
|
+
req: Request,
|
|
26
|
+
res: Response
|
|
27
|
+
) {
|
|
28
|
+
console.log("req.body", req.body);
|
|
29
|
+
res.json({ test: "success" }).send();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Put()
|
|
33
|
+
private _put(
|
|
34
|
+
req: Request,
|
|
35
|
+
res: Response
|
|
36
|
+
) {
|
|
37
|
+
res.json({ test: "success" }).send();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Patch()
|
|
41
|
+
private _patch(
|
|
42
|
+
req: Request,
|
|
43
|
+
res: Response
|
|
44
|
+
) {
|
|
45
|
+
res.json({ test: "success" }).send();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Delete()
|
|
49
|
+
private _delete(
|
|
50
|
+
req: Request,
|
|
51
|
+
res: Response
|
|
52
|
+
) {
|
|
53
|
+
res.json({ test: "success" }).send();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Options()
|
|
57
|
+
private _options(
|
|
58
|
+
req: Request,
|
|
59
|
+
res: Response
|
|
60
|
+
) {
|
|
61
|
+
res.json({ test: "success" }).send();
|
|
62
|
+
}
|
|
63
|
+
}
|
package/__test/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
import { BoolFactory } from "../src";
|
|
4
|
-
import { TestModule } from "./module";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const app = BoolFactory(TestModule);
|
|
8
|
-
|
|
9
|
-
app.listen(3000, () => {
|
|
10
|
-
console.log(`Listening on port ${3000}...`);
|
|
11
|
-
});
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
|
|
3
|
+
import { BoolFactory } from "../src";
|
|
4
|
+
import { TestModule } from "./module";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const app = BoolFactory(TestModule);
|
|
8
|
+
|
|
9
|
+
app.listen(3000, () => {
|
|
10
|
+
console.log(`Listening on port ${3000}...`);
|
|
11
|
+
});
|
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,17 +1,17 @@
|
|
|
1
|
-
import { Module } from "../src";
|
|
2
|
-
import { TestController } from "./controller";
|
|
3
|
-
// import { TestRepository } from "./repository";
|
|
4
|
-
import { TestService } from "./service";
|
|
5
|
-
|
|
6
|
-
@Module({
|
|
7
|
-
controllers: [
|
|
8
|
-
TestController
|
|
9
|
-
],
|
|
10
|
-
dependencies: [
|
|
11
|
-
// TestService,
|
|
12
|
-
// TestRepository
|
|
13
|
-
]
|
|
14
|
-
})
|
|
15
|
-
export class TestModule { }
|
|
16
|
-
|
|
17
|
-
export default TestModule;
|
|
1
|
+
import { Module } from "../src";
|
|
2
|
+
import { TestController } from "./controller";
|
|
3
|
+
// import { TestRepository } from "./repository";
|
|
4
|
+
import { TestService } from "./service";
|
|
5
|
+
|
|
6
|
+
@Module({
|
|
7
|
+
controllers: [
|
|
8
|
+
TestController
|
|
9
|
+
],
|
|
10
|
+
dependencies: [
|
|
11
|
+
// TestService,
|
|
12
|
+
// TestRepository
|
|
13
|
+
]
|
|
14
|
+
})
|
|
15
|
+
export class TestModule { }
|
|
16
|
+
|
|
17
|
+
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
|
Binary file
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Controller = exports.controllerKey = void 0;
|
|
4
|
+
const injectable_1 = require("./injectable");
|
|
5
|
+
exports.controllerKey = "__bool:controller__";
|
|
6
|
+
const Controller = (prefix) => (target, context) => {
|
|
7
|
+
Reflect.defineMetadata(exports.controllerKey, !prefix.startsWith("/") ? `/${prefix}` : prefix, target);
|
|
8
|
+
Reflect.defineMetadata(injectable_1.injectableKey, undefined, target);
|
|
6
9
|
return target;
|
|
7
10
|
};
|
|
8
|
-
|
|
11
|
+
exports.Controller = Controller;
|
|
12
|
+
exports.default = exports.Controller;
|
package/dist/decorators/http.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Options = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = exports.controllerRoutesKey = void 0;
|
|
4
|
+
exports.controllerRoutesKey = "__bool:controller.routes__";
|
|
2
5
|
/**
|
|
3
6
|
*
|
|
4
7
|
* @param path
|
|
5
8
|
* @returns
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
const Get = (path = "/") => (target, methodName, descriptor) => {
|
|
8
11
|
if (typeof descriptor.value !== "function") {
|
|
9
12
|
throw Error("Get decorator only use for method.");
|
|
10
13
|
}
|
|
11
|
-
Reflect.defineMetadata(controllerRoutesKey, [
|
|
12
|
-
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
14
|
+
Reflect.defineMetadata(exports.controllerRoutesKey, [
|
|
15
|
+
...Reflect.getOwnMetadata(exports.controllerRoutesKey, target.constructor) || [],
|
|
13
16
|
{
|
|
14
17
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
15
18
|
httpMethod: "GET",
|
|
@@ -18,17 +21,18 @@ export const Get = (path = "/") => (target, methodName, descriptor) => {
|
|
|
18
21
|
}
|
|
19
22
|
], target.constructor);
|
|
20
23
|
};
|
|
24
|
+
exports.Get = Get;
|
|
21
25
|
/**
|
|
22
26
|
*
|
|
23
27
|
* @param path
|
|
24
28
|
* @returns
|
|
25
29
|
*/
|
|
26
|
-
|
|
30
|
+
const Post = (path = "/") => (target, methodName, descriptor) => {
|
|
27
31
|
if (typeof descriptor.value !== "function") {
|
|
28
32
|
throw Error("Post decorator only use for method.");
|
|
29
33
|
}
|
|
30
|
-
Reflect.defineMetadata(controllerRoutesKey, [
|
|
31
|
-
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
34
|
+
Reflect.defineMetadata(exports.controllerRoutesKey, [
|
|
35
|
+
...Reflect.getOwnMetadata(exports.controllerRoutesKey, target.constructor) || [],
|
|
32
36
|
{
|
|
33
37
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
34
38
|
httpMethod: "POST",
|
|
@@ -37,17 +41,18 @@ export const Post = (path = "/") => (target, methodName, descriptor) => {
|
|
|
37
41
|
}
|
|
38
42
|
], target.constructor);
|
|
39
43
|
};
|
|
44
|
+
exports.Post = Post;
|
|
40
45
|
/**
|
|
41
46
|
*
|
|
42
47
|
* @param path
|
|
43
48
|
* @returns
|
|
44
49
|
*/
|
|
45
|
-
|
|
50
|
+
const Put = (path = "/") => (target, methodName, descriptor) => {
|
|
46
51
|
if (typeof descriptor.value !== "function") {
|
|
47
52
|
throw Error("Put decorator only use for method.");
|
|
48
53
|
}
|
|
49
|
-
Reflect.defineMetadata(controllerRoutesKey, [
|
|
50
|
-
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
54
|
+
Reflect.defineMetadata(exports.controllerRoutesKey, [
|
|
55
|
+
...Reflect.getOwnMetadata(exports.controllerRoutesKey, target.constructor) || [],
|
|
51
56
|
{
|
|
52
57
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
53
58
|
httpMethod: "PUT",
|
|
@@ -56,17 +61,18 @@ export const Put = (path = "/") => (target, methodName, descriptor) => {
|
|
|
56
61
|
}
|
|
57
62
|
], target.constructor);
|
|
58
63
|
};
|
|
64
|
+
exports.Put = Put;
|
|
59
65
|
/**
|
|
60
66
|
*
|
|
61
67
|
* @param path
|
|
62
68
|
* @returns
|
|
63
69
|
*/
|
|
64
|
-
|
|
70
|
+
const Patch = (path = "/") => (target, methodName, descriptor) => {
|
|
65
71
|
if (typeof descriptor.value !== "function") {
|
|
66
72
|
throw Error("Patch decorator only use for method.");
|
|
67
73
|
}
|
|
68
|
-
Reflect.defineMetadata(controllerRoutesKey, [
|
|
69
|
-
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
74
|
+
Reflect.defineMetadata(exports.controllerRoutesKey, [
|
|
75
|
+
...Reflect.getOwnMetadata(exports.controllerRoutesKey, target.constructor) || [],
|
|
70
76
|
{
|
|
71
77
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
72
78
|
httpMethod: "PATCH",
|
|
@@ -75,17 +81,18 @@ export const Patch = (path = "/") => (target, methodName, descriptor) => {
|
|
|
75
81
|
}
|
|
76
82
|
], target.constructor);
|
|
77
83
|
};
|
|
84
|
+
exports.Patch = Patch;
|
|
78
85
|
/**
|
|
79
86
|
*
|
|
80
87
|
* @param path
|
|
81
88
|
* @returns
|
|
82
89
|
*/
|
|
83
|
-
|
|
90
|
+
const Delete = (path = "/") => (target, methodName, descriptor) => {
|
|
84
91
|
if (typeof descriptor.value !== "function") {
|
|
85
92
|
throw Error("Delete decorator only use for method.");
|
|
86
93
|
}
|
|
87
|
-
Reflect.defineMetadata(controllerRoutesKey, [
|
|
88
|
-
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
94
|
+
Reflect.defineMetadata(exports.controllerRoutesKey, [
|
|
95
|
+
...Reflect.getOwnMetadata(exports.controllerRoutesKey, target.constructor) || [],
|
|
89
96
|
{
|
|
90
97
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
91
98
|
httpMethod: "DELETE",
|
|
@@ -94,17 +101,18 @@ export const Delete = (path = "/") => (target, methodName, descriptor) => {
|
|
|
94
101
|
}
|
|
95
102
|
], target.constructor);
|
|
96
103
|
};
|
|
104
|
+
exports.Delete = Delete;
|
|
97
105
|
/**
|
|
98
106
|
*
|
|
99
107
|
* @param path
|
|
100
108
|
* @returns
|
|
101
109
|
*/
|
|
102
|
-
|
|
110
|
+
const Options = (path = "/") => (target, methodName, descriptor) => {
|
|
103
111
|
if (typeof descriptor.value !== "function") {
|
|
104
112
|
throw Error("Options decorator only use for method.");
|
|
105
113
|
}
|
|
106
|
-
Reflect.defineMetadata(controllerRoutesKey, [
|
|
107
|
-
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
114
|
+
Reflect.defineMetadata(exports.controllerRoutesKey, [
|
|
115
|
+
...Reflect.getOwnMetadata(exports.controllerRoutesKey, target.constructor) || [],
|
|
108
116
|
{
|
|
109
117
|
path: !path.startsWith("/") ? `/${path}` : path,
|
|
110
118
|
httpMethod: "OPTIONS",
|
|
@@ -113,10 +121,11 @@ export const Options = (path = "/") => (target, methodName, descriptor) => {
|
|
|
113
121
|
}
|
|
114
122
|
], target.constructor);
|
|
115
123
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
exports.Options = Options;
|
|
125
|
+
exports.default = {
|
|
126
|
+
Get: exports.Get,
|
|
127
|
+
Post: exports.Post,
|
|
128
|
+
Put: exports.Put,
|
|
129
|
+
Patch: exports.Patch,
|
|
130
|
+
Delete: exports.Delete
|
|
122
131
|
};
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.controllerRoutesKey = exports.Options = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = exports.moduleKey = exports.Module = exports.injectableKey = exports.Injectable = exports.injectKey = exports.Inject = exports.controllerKey = exports.Controller = void 0;
|
|
4
|
+
var controller_1 = require("./controller");
|
|
5
|
+
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return controller_1.Controller; } });
|
|
6
|
+
Object.defineProperty(exports, "controllerKey", { enumerable: true, get: function () { return controller_1.controllerKey; } });
|
|
7
|
+
var inject_1 = require("./inject");
|
|
8
|
+
Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return inject_1.Inject; } });
|
|
9
|
+
Object.defineProperty(exports, "injectKey", { enumerable: true, get: function () { return inject_1.injectKey; } });
|
|
10
|
+
var injectable_1 = require("./injectable");
|
|
11
|
+
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return injectable_1.Injectable; } });
|
|
12
|
+
Object.defineProperty(exports, "injectableKey", { enumerable: true, get: function () { return injectable_1.injectableKey; } });
|
|
13
|
+
var module_1 = require("./module");
|
|
14
|
+
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return module_1.Module; } });
|
|
15
|
+
Object.defineProperty(exports, "moduleKey", { enumerable: true, get: function () { return module_1.moduleKey; } });
|
|
16
|
+
var http_1 = require("./http");
|
|
17
|
+
Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return http_1.Get; } });
|
|
18
|
+
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return http_1.Post; } });
|
|
19
|
+
Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return http_1.Put; } });
|
|
20
|
+
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return http_1.Patch; } });
|
|
21
|
+
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return http_1.Delete; } });
|
|
22
|
+
Object.defineProperty(exports, "Options", { enumerable: true, get: function () { return http_1.Options; } });
|
|
23
|
+
Object.defineProperty(exports, "controllerRoutesKey", { enumerable: true, get: function () { return http_1.controllerRoutesKey; } });
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Inject = exports.injectKey = void 0;
|
|
4
|
+
exports.injectKey = "design:paramtypes";
|
|
5
|
+
const Inject = (classDefinition) => {
|
|
3
6
|
return (target, parameterName, parameterIndex) => {
|
|
4
|
-
const designParameterTypes = Reflect.getMetadata(injectKey, target) || [];
|
|
7
|
+
const designParameterTypes = Reflect.getMetadata(exports.injectKey, target) || [];
|
|
5
8
|
designParameterTypes[parameterIndex] = classDefinition;
|
|
6
|
-
Reflect.defineMetadata(injectKey, designParameterTypes, target);
|
|
9
|
+
Reflect.defineMetadata(exports.injectKey, designParameterTypes, target);
|
|
7
10
|
};
|
|
8
11
|
};
|
|
9
|
-
|
|
12
|
+
exports.Inject = Inject;
|
|
13
|
+
exports.default = exports.Inject;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Injectable = exports.injectableKey = void 0;
|
|
4
|
+
exports.injectableKey = "__bool:injectable__";
|
|
5
|
+
const Injectable = () => (target, context) => {
|
|
6
|
+
Reflect.defineMetadata(exports.injectableKey, undefined, target);
|
|
4
7
|
return target;
|
|
5
8
|
};
|
|
6
|
-
|
|
9
|
+
exports.Injectable = Injectable;
|
|
10
|
+
exports.default = exports.Injectable;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = exports.moduleKey = void 0;
|
|
4
|
+
exports.moduleKey = "__bool:module__";
|
|
5
|
+
const Module = (args) => (target, context) => {
|
|
6
|
+
Reflect.defineMetadata(exports.moduleKey, args, target);
|
|
4
7
|
return target;
|
|
5
8
|
};
|
|
6
|
-
|
|
9
|
+
exports.Module = Module;
|
|
10
|
+
exports.default = exports.Module;
|