@bool-ts/core 1.0.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/LICENSE +21 -0
- package/README.md +1 -0
- package/__test/controller.d.ts +11 -0
- package/__test/controller.js +59 -0
- package/__test/controller.ts +62 -0
- package/__test/index.d.ts +1 -0
- package/__test/index.js +7 -0
- package/__test/index.ts +11 -0
- package/__test/interfaces.d.ts +6 -0
- package/__test/interfaces.js +0 -0
- package/__test/interfaces.ts +7 -0
- package/__test/module.d.ts +3 -0
- package/__test/module.js +24 -0
- package/__test/module.ts +17 -0
- package/__test/repository.d.ts +8 -0
- package/__test/repository.js +20 -0
- package/__test/repository.ts +16 -0
- package/__test/router.d.ts +0 -0
- package/__test/router.js +1 -0
- package/__test/router.ts +0 -0
- package/__test/service.d.ts +9 -0
- package/__test/service.js +29 -0
- package/__test/service.ts +20 -0
- package/bun.lockb +0 -0
- package/dist/decorators/controller.d.ts +3 -0
- package/dist/decorators/controller.js +8 -0
- package/dist/decorators/http.d.ts +51 -0
- package/dist/decorators/http.js +122 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.js +5 -0
- package/dist/decorators/inject.d.ts +3 -0
- package/dist/decorators/inject.js +9 -0
- package/dist/decorators/injectable.d.ts +3 -0
- package/dist/decorators/injectable.js +6 -0
- package/dist/decorators/module.d.ts +7 -0
- package/dist/decorators/module.js +6 -0
- package/dist/hooks/factory.d.ts +8 -0
- package/dist/hooks/factory.js +119 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/injector.d.ts +6 -0
- package/dist/hooks/injector.js +23 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +1 -0
- package/package.json +33 -0
- package/src/decorators/controller.ts +18 -0
- package/src/decorators/http.ts +185 -0
- package/src/decorators/index.ts +5 -0
- package/src/decorators/inject.ts +19 -0
- package/src/decorators/injectable.ts +12 -0
- package/src/decorators/module.ts +19 -0
- package/src/hooks/factory.ts +151 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/injector.ts +39 -0
- package/src/index.ts +5 -0
- package/src/interfaces/index.ts +3 -0
- package/test.http +28 -0
- package/tsconfig.json +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# core
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IService } from "./interfaces";
|
|
2
|
+
export declare class TestController {
|
|
3
|
+
private readonly testService;
|
|
4
|
+
constructor(testService: IService);
|
|
5
|
+
private _get;
|
|
6
|
+
private _post;
|
|
7
|
+
private _put;
|
|
8
|
+
private _patch;
|
|
9
|
+
private _delete;
|
|
10
|
+
private _options;
|
|
11
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Controller, Delete, Get, Inject, Options, Patch, Post, Put } from "../src";
|
|
11
|
+
import { TestService } from "./service";
|
|
12
|
+
let TestController = class TestController {
|
|
13
|
+
testService;
|
|
14
|
+
constructor(testService) {
|
|
15
|
+
this.testService = testService;
|
|
16
|
+
}
|
|
17
|
+
_get(req, res) {
|
|
18
|
+
res.json({ test: "success" }).send();
|
|
19
|
+
}
|
|
20
|
+
_post(req, res) {
|
|
21
|
+
console.log("req.body", req.body);
|
|
22
|
+
res.json({ test: "success" }).send();
|
|
23
|
+
}
|
|
24
|
+
_put(req, res) {
|
|
25
|
+
res.json({ test: "success" }).send();
|
|
26
|
+
}
|
|
27
|
+
_patch(req, res) {
|
|
28
|
+
res.json({ test: "success" }).send();
|
|
29
|
+
}
|
|
30
|
+
_delete(req, res) {
|
|
31
|
+
res.json({ test: "success" }).send();
|
|
32
|
+
}
|
|
33
|
+
_options(req, res) {
|
|
34
|
+
res.json({ test: "success" }).send();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
Get()
|
|
39
|
+
], TestController.prototype, "_get", null);
|
|
40
|
+
__decorate([
|
|
41
|
+
Post()
|
|
42
|
+
], TestController.prototype, "_post", null);
|
|
43
|
+
__decorate([
|
|
44
|
+
Put()
|
|
45
|
+
], TestController.prototype, "_put", null);
|
|
46
|
+
__decorate([
|
|
47
|
+
Patch()
|
|
48
|
+
], TestController.prototype, "_patch", null);
|
|
49
|
+
__decorate([
|
|
50
|
+
Delete()
|
|
51
|
+
], TestController.prototype, "_delete", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
Options()
|
|
54
|
+
], TestController.prototype, "_options", null);
|
|
55
|
+
TestController = __decorate([
|
|
56
|
+
Controller("test"),
|
|
57
|
+
__param(0, Inject(TestService))
|
|
58
|
+
], TestController);
|
|
59
|
+
export { TestController };
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
res.json({ test: "success" }).send();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Post()
|
|
23
|
+
private _post(
|
|
24
|
+
req: Request,
|
|
25
|
+
res: Response
|
|
26
|
+
) {
|
|
27
|
+
console.log("req.body", req.body);
|
|
28
|
+
res.json({ test: "success" }).send();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Put()
|
|
32
|
+
private _put(
|
|
33
|
+
req: Request,
|
|
34
|
+
res: Response
|
|
35
|
+
) {
|
|
36
|
+
res.json({ test: "success" }).send();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Patch()
|
|
40
|
+
private _patch(
|
|
41
|
+
req: Request,
|
|
42
|
+
res: Response
|
|
43
|
+
) {
|
|
44
|
+
res.json({ test: "success" }).send();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Delete()
|
|
48
|
+
private _delete(
|
|
49
|
+
req: Request,
|
|
50
|
+
res: Response
|
|
51
|
+
) {
|
|
52
|
+
res.json({ test: "success" }).send();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Options()
|
|
56
|
+
private _options(
|
|
57
|
+
req: Request,
|
|
58
|
+
res: Response
|
|
59
|
+
) {
|
|
60
|
+
res.json({ test: "success" }).send();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "reflect-metadata";
|
package/__test/index.js
ADDED
package/__test/index.ts
ADDED
|
File without changes
|
package/__test/module.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from "../src";
|
|
8
|
+
import { TestController } from "./controller";
|
|
9
|
+
import { TestService } from "./service";
|
|
10
|
+
let TestModule = class TestModule {
|
|
11
|
+
};
|
|
12
|
+
TestModule = __decorate([
|
|
13
|
+
Module({
|
|
14
|
+
controllers: [
|
|
15
|
+
TestController
|
|
16
|
+
],
|
|
17
|
+
dependencies: [
|
|
18
|
+
TestService,
|
|
19
|
+
// TestRepository
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
], TestModule);
|
|
23
|
+
export { TestModule };
|
|
24
|
+
export default TestModule;
|
package/__test/module.ts
ADDED
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Injectable } from "../src";
|
|
8
|
+
let TestRepository = class TestRepository {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
exec() {
|
|
13
|
+
console.log("This is test repository.");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
TestRepository = __decorate([
|
|
17
|
+
Injectable()
|
|
18
|
+
], TestRepository);
|
|
19
|
+
export { TestRepository };
|
|
20
|
+
export default TestRepository;
|
|
@@ -0,0 +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;
|
|
File without changes
|
package/__test/router.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/__test/router.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable } from "../src";
|
|
11
|
+
import { TestRepository } from "./repository";
|
|
12
|
+
let TestService = class TestService {
|
|
13
|
+
testRepository;
|
|
14
|
+
constructor(testRepository) {
|
|
15
|
+
this.testRepository = testRepository;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
exec() {
|
|
21
|
+
console.log("This is test service.", this.testRepository);
|
|
22
|
+
this.testRepository.exec();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
TestService = __decorate([
|
|
26
|
+
Injectable(),
|
|
27
|
+
__param(0, Inject(TestRepository))
|
|
28
|
+
], TestService);
|
|
29
|
+
export { TestService };
|
|
@@ -0,0 +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
|
+
}
|
package/bun.lockb
ADDED
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { injectableKey } from "./injectable";
|
|
2
|
+
export const controllerKey = "__bool:controller__";
|
|
3
|
+
export const Controller = (prefix) => (target, context) => {
|
|
4
|
+
Reflect.defineMetadata(controllerKey, !prefix.startsWith("/") ? `/${prefix}` : prefix, target);
|
|
5
|
+
Reflect.defineMetadata(injectableKey, undefined, target);
|
|
6
|
+
return target;
|
|
7
|
+
};
|
|
8
|
+
export default Controller;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface IControllerRoute {
|
|
2
|
+
path: string;
|
|
3
|
+
httpMethod: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
|
|
4
|
+
methodName: string;
|
|
5
|
+
descriptor: PropertyDescriptor;
|
|
6
|
+
}
|
|
7
|
+
export declare const controllerRoutesKey = "__bool:controller.routes__";
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param path
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const Get: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param path
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const Post: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param path
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare const Put: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param path
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const Patch: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param path
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare const Delete: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param path
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export declare const Options: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
44
|
+
declare const _default: {
|
|
45
|
+
Get: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
46
|
+
Post: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
47
|
+
Put: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
48
|
+
Patch: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
49
|
+
Delete: (path?: string) => (target: Object, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
50
|
+
};
|
|
51
|
+
export default _default;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const controllerRoutesKey = "__bool:controller.routes__";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param path
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export const Get = (path = "/") => (target, methodName, descriptor) => {
|
|
8
|
+
if (typeof descriptor.value !== "function") {
|
|
9
|
+
throw Error("Get decorator only use for method.");
|
|
10
|
+
}
|
|
11
|
+
Reflect.defineMetadata(controllerRoutesKey, [
|
|
12
|
+
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
13
|
+
{
|
|
14
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
15
|
+
httpMethod: "GET",
|
|
16
|
+
methodName: methodName,
|
|
17
|
+
descriptor: descriptor
|
|
18
|
+
}
|
|
19
|
+
], target.constructor);
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param path
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export const Post = (path = "/") => (target, methodName, descriptor) => {
|
|
27
|
+
if (typeof descriptor.value !== "function") {
|
|
28
|
+
throw Error("Post decorator only use for method.");
|
|
29
|
+
}
|
|
30
|
+
Reflect.defineMetadata(controllerRoutesKey, [
|
|
31
|
+
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
32
|
+
{
|
|
33
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
34
|
+
httpMethod: "POST",
|
|
35
|
+
methodName: methodName,
|
|
36
|
+
descriptor: descriptor
|
|
37
|
+
}
|
|
38
|
+
], target.constructor);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param path
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export const Put = (path = "/") => (target, methodName, descriptor) => {
|
|
46
|
+
if (typeof descriptor.value !== "function") {
|
|
47
|
+
throw Error("Put decorator only use for method.");
|
|
48
|
+
}
|
|
49
|
+
Reflect.defineMetadata(controllerRoutesKey, [
|
|
50
|
+
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
51
|
+
{
|
|
52
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
53
|
+
httpMethod: "PUT",
|
|
54
|
+
methodName: methodName,
|
|
55
|
+
descriptor: descriptor
|
|
56
|
+
}
|
|
57
|
+
], target.constructor);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param path
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
export const Patch = (path = "/") => (target, methodName, descriptor) => {
|
|
65
|
+
if (typeof descriptor.value !== "function") {
|
|
66
|
+
throw Error("Patch decorator only use for method.");
|
|
67
|
+
}
|
|
68
|
+
Reflect.defineMetadata(controllerRoutesKey, [
|
|
69
|
+
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
70
|
+
{
|
|
71
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
72
|
+
httpMethod: "PATCH",
|
|
73
|
+
methodName: methodName,
|
|
74
|
+
descriptor: descriptor
|
|
75
|
+
}
|
|
76
|
+
], target.constructor);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param path
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
export const Delete = (path = "/") => (target, methodName, descriptor) => {
|
|
84
|
+
if (typeof descriptor.value !== "function") {
|
|
85
|
+
throw Error("Delete decorator only use for method.");
|
|
86
|
+
}
|
|
87
|
+
Reflect.defineMetadata(controllerRoutesKey, [
|
|
88
|
+
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
89
|
+
{
|
|
90
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
91
|
+
httpMethod: "DELETE",
|
|
92
|
+
methodName: methodName,
|
|
93
|
+
descriptor: descriptor
|
|
94
|
+
}
|
|
95
|
+
], target.constructor);
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param path
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
export const Options = (path = "/") => (target, methodName, descriptor) => {
|
|
103
|
+
if (typeof descriptor.value !== "function") {
|
|
104
|
+
throw Error("Options decorator only use for method.");
|
|
105
|
+
}
|
|
106
|
+
Reflect.defineMetadata(controllerRoutesKey, [
|
|
107
|
+
...Reflect.getOwnMetadata(controllerRoutesKey, target.constructor) || [],
|
|
108
|
+
{
|
|
109
|
+
path: !path.startsWith("/") ? `/${path}` : path,
|
|
110
|
+
httpMethod: "OPTIONS",
|
|
111
|
+
methodName: methodName,
|
|
112
|
+
descriptor: descriptor
|
|
113
|
+
}
|
|
114
|
+
], target.constructor);
|
|
115
|
+
};
|
|
116
|
+
export default {
|
|
117
|
+
Get,
|
|
118
|
+
Post,
|
|
119
|
+
Put,
|
|
120
|
+
Patch,
|
|
121
|
+
Delete
|
|
122
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Controller, controllerKey } from "./controller";
|
|
2
|
+
export { Inject, injectKey } from "./inject";
|
|
3
|
+
export { Injectable, injectableKey } from "./injectable";
|
|
4
|
+
export { Module, moduleKey, type TModuleOptions } from "./module";
|
|
5
|
+
export { Get, Post, Put, Patch, Delete, Options, controllerRoutesKey, type IControllerRoute } from "./http";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Controller, controllerKey } from "./controller";
|
|
2
|
+
export { Inject, injectKey } from "./inject";
|
|
3
|
+
export { Injectable, injectableKey } from "./injectable";
|
|
4
|
+
export { Module, moduleKey } from "./module";
|
|
5
|
+
export { Get, Post, Put, Patch, Delete, Options, controllerRoutesKey } from "./http";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const injectKey = "design:paramtypes";
|
|
2
|
+
export const Inject = (constructor) => {
|
|
3
|
+
return (target, parameterName, parameterIndex) => {
|
|
4
|
+
const designParameterTypes = Reflect.getMetadata(injectKey, target.constructor) || [];
|
|
5
|
+
designParameterTypes[parameterIndex] = constructor;
|
|
6
|
+
Reflect.defineMetadata(injectKey, designParameterTypes, target.constructor);
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export default Inject;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type TModuleOptions = Partial<{
|
|
2
|
+
controllers: Array<new (...args: any[]) => unknown>;
|
|
3
|
+
dependencies: Array<new (...args: any[]) => unknown>;
|
|
4
|
+
}> | undefined;
|
|
5
|
+
export declare const moduleKey = "__bool:module__";
|
|
6
|
+
export declare const Module: (args?: TModuleOptions) => <T extends new (...args: any[]) => {}>(target: T, context?: ClassDecoratorContext) => T;
|
|
7
|
+
export default Module;
|