web_api_base 1.0.0 → 1.1.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/dist/App.js +32 -0
- package/dist/App.js.map +1 -0
- package/dist/Application.d.ts +10 -0
- package/dist/Application.js +33 -0
- package/dist/Application.js.map +1 -0
- package/dist/ApplicationConfiguration.d.ts +10 -0
- package/dist/ApplicationConfiguration.js +69 -0
- package/dist/ApplicationConfiguration.js.map +1 -0
- package/dist/Configuration.js +69 -0
- package/dist/Configuration.js.map +1 -0
- package/dist/Index.js +23 -0
- package/dist/Index.js.map +1 -0
- package/dist/__tests__/classes/Controller.d.ts +8 -0
- package/dist/__tests__/classes/Controller.js +54 -0
- package/dist/__tests__/classes/Controller.js.map +1 -0
- package/dist/__tests__/decorators/controllers/ControllerDecorators.spec.d.ts +1 -0
- package/dist/__tests__/decorators/controllers/ControllerDecorators.spec.js +40 -0
- package/dist/__tests__/decorators/controllers/ControllerDecorators.spec.js.map +1 -0
- package/dist/config.json +1 -0
- package/dist/controllers/FileController.js +162 -0
- package/dist/controllers/FileController.js.map +1 -0
- package/dist/controllers/StatusController.js +44 -0
- package/dist/controllers/StatusController.js.map +1 -0
- package/dist/controllers/base/ControllerBase.d.ts +16 -0
- package/dist/controllers/base/ControllerBase.js +79 -0
- package/dist/controllers/base/ControllerBase.js.map +1 -0
- package/dist/decorators/controllers/ControllerDecorators.d.ts +36 -0
- package/dist/decorators/controllers/ControllerDecorators.js +104 -0
- package/dist/decorators/controllers/ControllerDecorators.js.map +1 -0
- package/dist/dependencyInjection/DependecyService.d.ts +9 -0
- package/dist/dependencyInjection/DependecyService.js +23 -0
- package/dist/dependencyInjection/DependecyService.js.map +1 -0
- package/dist/enums/httpVerbs/HttpVerbs.d.ts +6 -0
- package/dist/enums/httpVerbs/HttpVerbs.js +11 -0
- package/dist/enums/httpVerbs/HttpVerbs.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/interfaces/IApplication.d.ts +7 -0
- package/dist/interfaces/IApplication.js +3 -0
- package/dist/interfaces/IApplication.js.map +1 -0
- package/dist/interfaces/IApplicationConfiguration.d.ts +5 -0
- package/dist/interfaces/IApplicationConfiguration.js +3 -0
- package/dist/interfaces/IApplicationConfiguration.js.map +1 -0
- package/dist/interfaces/IController.d.ts +5 -0
- package/dist/interfaces/IController.js +3 -0
- package/dist/interfaces/IController.js.map +1 -0
- package/dist/interfaces/entities/IDirectory.d.ts +5 -0
- package/dist/interfaces/entities/IDirectory.js +3 -0
- package/dist/interfaces/entities/IDirectory.js.map +1 -0
- package/dist/jest.config.d.ts +0 -0
- package/dist/jest.config.js +8 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/midlewares/IMidleware.d.ts +4 -0
- package/dist/midlewares/IMidleware.js +3 -0
- package/dist/midlewares/IMidleware.js.map +1 -0
- package/dist/services/FileService.js +45 -0
- package/dist/services/FileService.js.map +1 -0
- package/dist/services/IFileService.js +8 -0
- package/dist/services/IFileService.js.map +1 -0
- package/dist/services/fileService/FileService.d.ts +10 -0
- package/dist/services/fileService/FileService.js +96 -0
- package/dist/services/fileService/FileService.js.map +1 -0
- package/dist/services/fileService/FileServiceBase.d.ts +10 -0
- package/dist/services/fileService/FileServiceBase.js +7 -0
- package/dist/services/fileService/FileServiceBase.js.map +1 -0
- package/package.json +7 -3
- package/.vscode/launch.json +0 -21
- package/Application.ts +0 -39
- package/ApplicationConfiguration.ts +0 -82
- package/__tests__/classes/Controller.ts +0 -38
- package/__tests__/decorators/controllers/ControllerDecorators.spec.ts +0 -67
- package/controllers/base/ControllerBase.ts +0 -116
- package/decorators/controllers/ControllerDecorators.ts +0 -187
- package/dependencyInjection/DependecyService.ts +0 -36
- package/enums/httpVerbs/HttpVerbs.ts +0 -7
- package/interfaces/IApplication.ts +0 -13
- package/interfaces/IApplicationConfiguration.ts +0 -6
- package/interfaces/IController.ts +0 -8
- package/interfaces/entities/IDirectory.ts +0 -6
- package/jest.config.ts +0 -6
- package/midlewares/IMidleware.ts +0 -6
- package/services/fileService/FileService.ts +0 -125
- package/services/fileService/FileServiceBase.ts +0 -16
- package/tsconfig.json +0 -103
package/.vscode/launch.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
"type": "node",
|
|
10
|
-
"request": "launch",
|
|
11
|
-
"name": "Launch Program",
|
|
12
|
-
"skipFiles": [
|
|
13
|
-
"<node_internals>/**"
|
|
14
|
-
],
|
|
15
|
-
"program": "${file}",
|
|
16
|
-
"outFiles": [
|
|
17
|
-
"${workspaceFolder}/**/*.js"
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
package/Application.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Express } from "express";
|
|
2
|
-
import ExpressModule from "express";
|
|
3
|
-
import ApplicationConfiguration from "./ApplicationConfiguration"
|
|
4
|
-
import IApplication from "./interfaces/IApplication";
|
|
5
|
-
import IApplicationConfiguration from "./interfaces/IApplicationConfiguration";
|
|
6
|
-
|
|
7
|
-
export default abstract class Application implements IApplication
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
private ApplicationConfiguration : IApplicationConfiguration;
|
|
11
|
-
|
|
12
|
-
public Express : Express;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor()
|
|
16
|
-
{
|
|
17
|
-
this.ApplicationConfiguration = new ApplicationConfiguration();
|
|
18
|
-
|
|
19
|
-
this.Express = ExpressModule();
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
public async StartAsync() : Promise<void>
|
|
25
|
-
{
|
|
26
|
-
await this.ApplicationConfiguration.StartAsync();
|
|
27
|
-
|
|
28
|
-
this.Configure(this.ApplicationConfiguration);
|
|
29
|
-
|
|
30
|
-
this.Express.listen(this.ApplicationConfiguration.Port, this.ApplicationConfiguration.Host, ()=>
|
|
31
|
-
{
|
|
32
|
-
console.log(`App running on ${this.ApplicationConfiguration.Host}:${this.ApplicationConfiguration.Port}`);
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public abstract Configure(appConfig : IApplicationConfiguration): void;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import File from 'fs';
|
|
2
|
-
|
|
3
|
-
import IApplicationConfiguration from './interfaces/IApplicationConfiguration';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default class Configuration implements IApplicationConfiguration
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
public Host : string = "0.0.0.0";
|
|
10
|
-
public Port : number = 5555;
|
|
11
|
-
|
|
12
|
-
constructor()
|
|
13
|
-
{
|
|
14
|
-
process.env["root_dir"] = __dirname;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public async StartAsync() : Promise<void>
|
|
18
|
-
{
|
|
19
|
-
if(!await this.CheckFileAsync())
|
|
20
|
-
{
|
|
21
|
-
await this.CreateFileAsync();
|
|
22
|
-
|
|
23
|
-
}else{
|
|
24
|
-
|
|
25
|
-
await this.ReadFileAsync();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private async CheckFileAsync() : Promise<boolean>
|
|
30
|
-
{
|
|
31
|
-
return new Promise<boolean>((resolve, _) => resolve(File.existsSync(`${__dirname}\\config.json`)));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private async ReadFileAsync() : Promise<boolean>
|
|
35
|
-
{
|
|
36
|
-
return new Promise<boolean>((resolve, _) =>
|
|
37
|
-
{
|
|
38
|
-
File.readFile(`${__dirname}\\config.json`, 'utf-8', (error, data) =>
|
|
39
|
-
{
|
|
40
|
-
if(error)
|
|
41
|
-
{
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let json : any = JSON.parse(data);
|
|
46
|
-
|
|
47
|
-
for(let key in this)
|
|
48
|
-
{
|
|
49
|
-
if(json[key] != undefined)
|
|
50
|
-
{
|
|
51
|
-
this[key] = json[key];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
resolve(true);
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private async CreateFileAsync() : Promise<boolean>
|
|
62
|
-
{
|
|
63
|
-
|
|
64
|
-
return new Promise<boolean>((resolve, _)=>{
|
|
65
|
-
|
|
66
|
-
File.writeFile(`${__dirname}\\config.json`, JSON.stringify(this), 'utf-8', error =>
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
if(error)
|
|
70
|
-
{
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
resolve(true);
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore next */
|
|
2
|
-
|
|
3
|
-
import { ControllerBase } from "../../controllers/base/ControllerBase";
|
|
4
|
-
import ControllersDecorators from "../../decorators/controllers/ControllerDecorators";
|
|
5
|
-
import { HTTPVerbs } from "../../enums/httpVerbs/HttpVerbs";
|
|
6
|
-
import IApplication from "../../interfaces/IApplication";
|
|
7
|
-
import {Request, Response} from 'express'
|
|
8
|
-
|
|
9
|
-
@ControllersDecorators.Route("/test")
|
|
10
|
-
export class ControllerTest extends ControllerBase
|
|
11
|
-
{
|
|
12
|
-
constructor()
|
|
13
|
-
{
|
|
14
|
-
super();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@ControllersDecorators.Action("Test")
|
|
18
|
-
@ControllersDecorators.Verb(HTTPVerbs.GET)
|
|
19
|
-
@ControllersDecorators.Argument<string>('name')
|
|
20
|
-
public TestAction(name : string)
|
|
21
|
-
{
|
|
22
|
-
console.log(name);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@ControllersDecorators.Action("Test")
|
|
26
|
-
@ControllersDecorators.Verb(HTTPVerbs.GET)
|
|
27
|
-
@ControllersDecorators.Argument<string, number>('name', 'age')
|
|
28
|
-
public TestActionTwo(name : string, age : number)
|
|
29
|
-
{
|
|
30
|
-
console.log(name, age);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
public AppendSync(application: IApplication): void
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { ControllerTest } from "../../classes/Controller";
|
|
2
|
-
import ControllersDecorators from "../../../decorators/controllers/ControllerDecorators";
|
|
3
|
-
import { HTTPVerbs } from "../../../enums/httpVerbs/HttpVerbs";
|
|
4
|
-
|
|
5
|
-
describe('testing controllers decorators', ()=>
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
test("action name", ()=>
|
|
9
|
-
{
|
|
10
|
-
var controller = new ControllerTest();
|
|
11
|
-
let action = ControllersDecorators.GetAction(controller, "TestAction");
|
|
12
|
-
expect(action).toBe("Test");
|
|
13
|
-
|
|
14
|
-
},10^5)
|
|
15
|
-
|
|
16
|
-
test("http verb", ()=>
|
|
17
|
-
{
|
|
18
|
-
var controller = new ControllerTest();
|
|
19
|
-
let verb = ControllersDecorators.GetVerb(controller, "TestAction");
|
|
20
|
-
expect(verb).toBe(HTTPVerbs.GET);
|
|
21
|
-
|
|
22
|
-
},10^5)
|
|
23
|
-
|
|
24
|
-
test("action with one arg", ()=>
|
|
25
|
-
{
|
|
26
|
-
var controller = new ControllerTest();
|
|
27
|
-
|
|
28
|
-
var handler = ControllersDecorators.GetArgumentsHandler(controller, 'TestAction');
|
|
29
|
-
|
|
30
|
-
var arr = handler?.CreateArgumentsList({name : "adriano"});
|
|
31
|
-
|
|
32
|
-
Reflect.apply(controller.TestAction, controller, arr ?? []);
|
|
33
|
-
|
|
34
|
-
expect(arr).not.toBeNull();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},10^5)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
test("action with two args", ()=>
|
|
41
|
-
{
|
|
42
|
-
var controller = new ControllerTest();
|
|
43
|
-
|
|
44
|
-
var handler = ControllersDecorators.GetArgumentsHandler(controller, 'TestActionTwo');
|
|
45
|
-
|
|
46
|
-
var arr = handler?.CreateArgumentsList({name : "adriano", age : 30});
|
|
47
|
-
|
|
48
|
-
Reflect.apply(controller.TestActionTwo, controller, arr ?? []);
|
|
49
|
-
|
|
50
|
-
expect(arr).not.toBeNull();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},10^5)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
test("controller route", ()=>
|
|
57
|
-
{
|
|
58
|
-
var controller = new ControllerTest();
|
|
59
|
-
|
|
60
|
-
var route = ControllersDecorators.GetRoute(controller);
|
|
61
|
-
|
|
62
|
-
expect(route!).toBe("/test");
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},10^5)
|
|
66
|
-
|
|
67
|
-
})
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import IController from "../../interfaces/IController";
|
|
2
|
-
import {Request, Response} from 'express'
|
|
3
|
-
import ControllersDecorators from '../../decorators/controllers/ControllerDecorators';
|
|
4
|
-
import DependecyService from '../../dependencyInjection/DependecyService';
|
|
5
|
-
import IApplication from "../../interfaces/IApplication";
|
|
6
|
-
import { HTTPVerbs } from "../../enums/httpVerbs/HttpVerbs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export class ControllerBase implements IController
|
|
10
|
-
{
|
|
11
|
-
Request : Request = {} as Request;
|
|
12
|
-
Response : Response = {} as Response;
|
|
13
|
-
|
|
14
|
-
constructor()
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public OK<T>(result : T)
|
|
20
|
-
{
|
|
21
|
-
this.Response.status(200);
|
|
22
|
-
this.Response.json(result);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public Created()
|
|
26
|
-
{
|
|
27
|
-
this.Response.status(201);
|
|
28
|
-
this.Response.end();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public BadRequest<T>(result : T)
|
|
32
|
-
{
|
|
33
|
-
this.Response.status(400);
|
|
34
|
-
this.Response.json(result);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public Error<T>(result : T)
|
|
38
|
-
{
|
|
39
|
-
this.Response.status(500);
|
|
40
|
-
this.Response.json(result);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public SendResponse<T>(status : number, result : T)
|
|
44
|
-
{
|
|
45
|
-
this.Response.status(status);
|
|
46
|
-
this.Response.json(result);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public static AppendController<T extends IController>(ctor : { new (...args : any[]) : T;}, application : IApplication) : void
|
|
50
|
-
{
|
|
51
|
-
let empty = new ctor() as any;
|
|
52
|
-
|
|
53
|
-
let methods = Reflect.ownKeys(empty.constructor.prototype).filter(m =>
|
|
54
|
-
{
|
|
55
|
-
return typeof empty[m] == "function" ;
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
let route = ControllersDecorators.GetRoute(empty);
|
|
59
|
-
|
|
60
|
-
if(!route)
|
|
61
|
-
return;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
for(let method of methods)
|
|
65
|
-
{
|
|
66
|
-
let action = ControllersDecorators.GetAction(empty, method.toString());
|
|
67
|
-
|
|
68
|
-
if(!action){
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let verb = ControllersDecorators.GetVerb(empty, method.toString());
|
|
73
|
-
|
|
74
|
-
if(!verb)
|
|
75
|
-
verb = HTTPVerbs.GET;
|
|
76
|
-
|
|
77
|
-
console.debug("appended : " , verb,`${route}${action}`);
|
|
78
|
-
|
|
79
|
-
(application.Express as any)[verb.toString().toLowerCase()](`${route}${action}`, (req : Request, resp : Response) =>
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
let midlewares = ControllersDecorators.GetMidlewares(empty).reverse();
|
|
83
|
-
|
|
84
|
-
midlewares.push(...ControllersDecorators.GetBefores(empty, method.toString()).reverse());
|
|
85
|
-
|
|
86
|
-
if(midlewares)
|
|
87
|
-
{
|
|
88
|
-
for(let method of midlewares)
|
|
89
|
-
{
|
|
90
|
-
method(req);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let args = ControllersDecorators.GetArgumentsHandler(empty, method.toString());
|
|
95
|
-
let params = [];
|
|
96
|
-
|
|
97
|
-
if(args)
|
|
98
|
-
{
|
|
99
|
-
if(args.Arguments.length > 0)
|
|
100
|
-
{
|
|
101
|
-
if(req.body && verb == (HTTPVerbs.POST || verb == HTTPVerbs.PUT))
|
|
102
|
-
params = args.CreateArgumentsList(req.body);
|
|
103
|
-
if(req.query)
|
|
104
|
-
params.push(...args.CreateArgumentsList(req.query))
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let controller = DependecyService.ResolveCtor(empty.constructor) as IController;
|
|
109
|
-
controller.Request = req;
|
|
110
|
-
controller.Response = resp;
|
|
111
|
-
(controller as any)[method](...params);
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { REFUSED } from 'dns';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
|
|
4
|
-
import { HTTPVerbs } from '../../enums/httpVerbs/HttpVerbs';
|
|
5
|
-
import IController from '../../interfaces/IController';
|
|
6
|
-
import IMidleware from '../../midlewares/IMidleware';
|
|
7
|
-
|
|
8
|
-
export default class ControllersDecorators
|
|
9
|
-
{
|
|
10
|
-
constructor()
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private static RouteKeyMetadata = "meta:controllerRoute";
|
|
16
|
-
private static ActionVerbKeyMetadata = "meta:actionVerb";
|
|
17
|
-
private static ActionNameKeyMetadata = "meta:actionName";
|
|
18
|
-
private static ArgumentsHandlerKeyMetadata = "meta:argHandler";
|
|
19
|
-
private static ControllerMidlewaresKeyMetadata = "meta:controllerMidlewaresKey";
|
|
20
|
-
private static ActionsMidlewaresKeyMetadata = "meta:actionMidlewaresKey";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
public static Route(route : string)
|
|
24
|
-
{
|
|
25
|
-
return function( target : Function)
|
|
26
|
-
{
|
|
27
|
-
Reflect.defineMetadata(ControllersDecorators.RouteKeyMetadata, route, target);
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public static Use(midleware : IMidleware)
|
|
33
|
-
{
|
|
34
|
-
return function( target : Function)
|
|
35
|
-
{
|
|
36
|
-
let current : IMidleware[] = Reflect.getMetadata(ControllersDecorators.ControllerMidlewaresKeyMetadata, target) ?? [];
|
|
37
|
-
|
|
38
|
-
current.push(midleware);
|
|
39
|
-
|
|
40
|
-
Reflect.defineMetadata(ControllersDecorators.ControllerMidlewaresKeyMetadata, current, target);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static GetMidlewares(controller : IController) : IMidleware[]
|
|
45
|
-
{
|
|
46
|
-
return Reflect.getMetadata(ControllersDecorators.ControllerMidlewaresKeyMetadata, controller.constructor) ?? [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public static Before(midleware : IMidleware)
|
|
50
|
-
{
|
|
51
|
-
return function( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor)
|
|
52
|
-
{
|
|
53
|
-
let current : IMidleware[] = Reflect.getMetadata(ControllersDecorators.ActionsMidlewaresKeyMetadata, target, methodName) ?? [];
|
|
54
|
-
|
|
55
|
-
current.push(midleware);
|
|
56
|
-
|
|
57
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.ActionsMidlewaresKeyMetadata, target, methodName, current);
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public static GetBefores(controller : IController, methodName : string) : IMidleware[]
|
|
63
|
-
{
|
|
64
|
-
return this.GetMetaData<IMidleware[]>(ControllersDecorators.ActionsMidlewaresKeyMetadata, controller, methodName) ?? [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public static GetRoute(controller : IController) : string | undefined
|
|
68
|
-
{
|
|
69
|
-
return Reflect.getMetadata(ControllersDecorators.RouteKeyMetadata, controller.constructor);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
public static Verb(verb : HTTPVerbs)
|
|
74
|
-
{
|
|
75
|
-
return function( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor)
|
|
76
|
-
{
|
|
77
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.ActionVerbKeyMetadata, target, methodName, verb);
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public static GetVerb(target : IController, methodName : string ) : HTTPVerbs | undefined
|
|
83
|
-
{
|
|
84
|
-
let meta = this.GetMetaData<HTTPVerbs>(ControllersDecorators.ActionVerbKeyMetadata, target, methodName);
|
|
85
|
-
|
|
86
|
-
return meta;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public static Action(actionName : String)
|
|
90
|
-
{
|
|
91
|
-
return function( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor)
|
|
92
|
-
{
|
|
93
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.ActionNameKeyMetadata, target, methodName, actionName);
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public static GetAction(target : IController, methodName : string ) : string | undefined
|
|
99
|
-
{
|
|
100
|
-
let meta = this.GetMetaData<string>(ControllersDecorators.ActionNameKeyMetadata, target, methodName);
|
|
101
|
-
|
|
102
|
-
return meta;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
public static Argument<T>(argName1 : string) : ( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor) => void
|
|
107
|
-
public static Argument<T, U>(argName1 : string, argName2?: string) : ( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor) => void
|
|
108
|
-
public static Argument<T, U, K>(argName1 : string, argName2?: string, argName3? : string) : ( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor) => void
|
|
109
|
-
public static Argument<T, U, K, Y>(argName1 : string, argName2?: string, argName3? : string, argName4? : string) : ( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor) => void
|
|
110
|
-
public static Argument<T, U, K, Y, J>(argName1 : string, argName2?: string, argName3? : string, argName4? : string, argName5? : string) : ( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor) => void
|
|
111
|
-
public static Argument<T, U, K, Y, J, V>(argName1 : string, argName2?: string, argName3? : string, argName4? : string, argName5? : string, argName6? : string) : ( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor) => void
|
|
112
|
-
{
|
|
113
|
-
return function( target : Object, methodName : string, propertyDescriptor : PropertyDescriptor)
|
|
114
|
-
{
|
|
115
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.ArgumentsHandlerKeyMetadata, target, methodName,
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Arguments : [argName1, argName2, argName3, argName4, argName5, argName6],
|
|
120
|
-
|
|
121
|
-
CreateArgumentsList : (args : any) =>
|
|
122
|
-
{
|
|
123
|
-
let results = [] as any[];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (argName1 && (args[argName1] as unknown as T) != undefined)
|
|
127
|
-
results[0] = args[argName1] as T;
|
|
128
|
-
|
|
129
|
-
if (argName2 && (args[argName2] as unknown as U) != undefined)
|
|
130
|
-
results[1] = args[argName2] as U;
|
|
131
|
-
|
|
132
|
-
if (argName3 && (args[argName3] as unknown as K) != undefined)
|
|
133
|
-
results[2] = args[argName3] as K;
|
|
134
|
-
|
|
135
|
-
if (argName4 && (args[argName4] as unknown as Y) != undefined)
|
|
136
|
-
results[3] = args[argName4] as Y;
|
|
137
|
-
|
|
138
|
-
if (argName5 && (args[argName5] as unknown as J) != undefined)
|
|
139
|
-
results[4] = args[argName5] as J;
|
|
140
|
-
|
|
141
|
-
if (argName6 && (args[argName6] as unknown as V) != undefined)
|
|
142
|
-
results[5] = args[argName6] as V;
|
|
143
|
-
|
|
144
|
-
return results;
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
public static GetArgumentsHandler(target : IController, methodName : string ) : IArgumentResolverHandler | undefined
|
|
155
|
-
{
|
|
156
|
-
let handler = this.GetMetaData<IArgumentResolverHandler>(ControllersDecorators.ArgumentsHandlerKeyMetadata, target, methodName);
|
|
157
|
-
|
|
158
|
-
return handler;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private static SetMetaData<T>(key: string, target : Object, methodName : string, value : T)
|
|
162
|
-
{
|
|
163
|
-
var meta = Reflect.getOwnMetadata(key, target as Object, methodName);
|
|
164
|
-
|
|
165
|
-
if(!meta)
|
|
166
|
-
Reflect.defineMetadata(key, value, target as Object, methodName);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
private static GetMetaData<T>(key: string, target : Object, methodName : string) : T | undefined
|
|
171
|
-
{
|
|
172
|
-
var meta = Reflect.getMetadata(key, target, methodName);
|
|
173
|
-
|
|
174
|
-
if(meta != undefined)
|
|
175
|
-
return meta as T;
|
|
176
|
-
else
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
interface IArgumentResolverHandler
|
|
182
|
-
{
|
|
183
|
-
Arguments : string[];
|
|
184
|
-
CreateArgumentsList : (args :any) => any[];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export default class DependecyService
|
|
2
|
-
{
|
|
3
|
-
private static _services : IService[] = [];
|
|
4
|
-
|
|
5
|
-
public static RegisterFor(type : Function, ctor : { new (...args : any[]) : any;}, builder? : () => any) : void
|
|
6
|
-
{
|
|
7
|
-
let defaultBuilder = () => Reflect.construct(ctor ?? type, []) as any;
|
|
8
|
-
|
|
9
|
-
this._services.push({ Type : type, Builder : builder ?? defaultBuilder });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public static Register(type : Function, builder? : () => any) : void
|
|
13
|
-
{
|
|
14
|
-
let defaultBuilder = () => Reflect.construct(type, []);
|
|
15
|
-
|
|
16
|
-
this._services.push({ Type : type, Builder : builder ?? defaultBuilder });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public static Resolve<T>(type : Function, args? : any[]) : T
|
|
20
|
-
{
|
|
21
|
-
return this._services.find(u => u.Type == type)?.Builder(args) as T;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static ResolveCtor(ctor : Function, args? : any[]) : any
|
|
25
|
-
{
|
|
26
|
-
return this._services.find(u => u.Type == ctor)?.Builder(args);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
interface IService
|
|
33
|
-
{
|
|
34
|
-
Type : Function;
|
|
35
|
-
Builder : Function;
|
|
36
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Express } from "express";
|
|
2
|
-
import IApplicationConfiguration from './IApplicationConfiguration';
|
|
3
|
-
|
|
4
|
-
import IController from "./IController";
|
|
5
|
-
|
|
6
|
-
export default interface IApplication
|
|
7
|
-
{
|
|
8
|
-
Express : Express;
|
|
9
|
-
|
|
10
|
-
StartAsync() : Promise<void>;
|
|
11
|
-
|
|
12
|
-
Configure(appConfig : IApplicationConfiguration): void;
|
|
13
|
-
}
|
package/jest.config.ts
DELETED