web_api_base 1.3.2 → 2.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/dist/Application.d.ts +6 -1
- package/dist/Application.js +90 -1
- package/dist/Application.js.map +1 -1
- package/dist/controllers/base/ControllerBase.d.ts +0 -4
- package/dist/controllers/base/ControllerBase.js +0 -48
- package/dist/controllers/base/ControllerBase.js.map +1 -1
- package/dist/interfaces/IApplication.d.ts +1 -1
- package/package.json +2 -1
- package/readme.md +86 -0
package/dist/Application.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Express } from "express";
|
|
2
2
|
import IApplication from "./interfaces/IApplication";
|
|
3
3
|
import IApplicationConfiguration from "./interfaces/IApplicationConfiguration";
|
|
4
|
+
import IController from "./interfaces/IController";
|
|
4
5
|
export default abstract class Application implements IApplication {
|
|
5
6
|
private ApplicationConfiguration;
|
|
6
7
|
Express: Express;
|
|
7
8
|
constructor();
|
|
8
9
|
StartAsync(): Promise<void>;
|
|
9
10
|
UseCors(): void;
|
|
10
|
-
|
|
11
|
+
protected UseControllers(): Promise<void>;
|
|
12
|
+
protected AppendController<T extends IController>(ctor: {
|
|
13
|
+
new (...args: any[]): T;
|
|
14
|
+
}): void;
|
|
15
|
+
abstract ConfigureAsync(appConfig: IApplicationConfiguration): Promise<void>;
|
|
11
16
|
}
|
package/dist/Application.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -14,6 +37,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
const express_1 = __importDefault(require("express"));
|
|
16
39
|
const ApplicationConfiguration_1 = __importDefault(require("./ApplicationConfiguration"));
|
|
40
|
+
const ControllerDecorators_1 = __importDefault(require("./decorators/controllers/ControllerDecorators"));
|
|
41
|
+
const DependecyService_1 = __importDefault(require("./dependencyInjection/DependecyService"));
|
|
42
|
+
const HttpVerbs_1 = require("./enums/httpVerbs/HttpVerbs");
|
|
43
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
|
+
const path_1 = __importDefault(require("path"));
|
|
17
45
|
class Application {
|
|
18
46
|
constructor() {
|
|
19
47
|
this.ApplicationConfiguration = new ApplicationConfiguration_1.default();
|
|
@@ -23,7 +51,7 @@ class Application {
|
|
|
23
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
52
|
yield this.ApplicationConfiguration.StartAsync();
|
|
25
53
|
this.Express.use(express_1.default.json({ limit: 50 * 1024 * 1024 }));
|
|
26
|
-
this.
|
|
54
|
+
yield this.ConfigureAsync(this.ApplicationConfiguration);
|
|
27
55
|
this.Express.listen(this.ApplicationConfiguration.Port, this.ApplicationConfiguration.Host, () => {
|
|
28
56
|
console.log(`App running on ${this.ApplicationConfiguration.Host}:${this.ApplicationConfiguration.Port}`);
|
|
29
57
|
});
|
|
@@ -32,6 +60,67 @@ class Application {
|
|
|
32
60
|
UseCors() {
|
|
33
61
|
this.Express.use(require('cors')());
|
|
34
62
|
}
|
|
63
|
+
UseControllers() {
|
|
64
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
let controllersPath = path_1.default.join(__dirname, "controllers");
|
|
66
|
+
if (!fs_1.default.existsSync(controllersPath))
|
|
67
|
+
return;
|
|
68
|
+
let files = fs_1.default.readdirSync(controllersPath).filter(s => s.toLocaleLowerCase().indexOf("controller") >= 0);
|
|
69
|
+
for (let controllerFile of files) {
|
|
70
|
+
try {
|
|
71
|
+
let controllerClass = yield Promise.resolve().then(() => __importStar(require(controllerFile)));
|
|
72
|
+
let controller = Reflect.construct(controllerClass.prototype.constructor, []);
|
|
73
|
+
if (controller != undefined && controller != null) {
|
|
74
|
+
this.AppendController(controllerClass.prototype.construct);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (_a) { }
|
|
78
|
+
}
|
|
79
|
+
resolve();
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
AppendController(ctor) {
|
|
83
|
+
let empty = new ctor();
|
|
84
|
+
let methods = Reflect.ownKeys(empty.constructor.prototype).filter(m => {
|
|
85
|
+
return typeof empty[m] == "function";
|
|
86
|
+
});
|
|
87
|
+
let route = ControllerDecorators_1.default.GetRoute(empty);
|
|
88
|
+
if (!route)
|
|
89
|
+
return;
|
|
90
|
+
for (let method of methods) {
|
|
91
|
+
let action = ControllerDecorators_1.default.GetAction(empty, method.toString());
|
|
92
|
+
if (!action) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
let verb = ControllerDecorators_1.default.GetVerb(empty, method.toString());
|
|
96
|
+
if (!verb)
|
|
97
|
+
verb = HttpVerbs_1.HTTPVerbs.GET;
|
|
98
|
+
console.debug("appended : ", verb, `${route}${action}`);
|
|
99
|
+
this.Express[verb.toString().toLowerCase()](`${route}${action}`, (req, resp) => {
|
|
100
|
+
let midlewares = ControllerDecorators_1.default.GetMidlewares(empty).reverse();
|
|
101
|
+
midlewares.push(...ControllerDecorators_1.default.GetBefores(empty, method.toString()).reverse());
|
|
102
|
+
if (midlewares) {
|
|
103
|
+
for (let method of midlewares) {
|
|
104
|
+
method(req);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let args = ControllerDecorators_1.default.GetArgumentsHandler(empty, method.toString());
|
|
108
|
+
let params = [];
|
|
109
|
+
if (args) {
|
|
110
|
+
if (args.Arguments.length > 0) {
|
|
111
|
+
if (req.body && verb == (HttpVerbs_1.HTTPVerbs.POST || verb == HttpVerbs_1.HTTPVerbs.PUT))
|
|
112
|
+
params = args.CreateArgumentsList(req.body);
|
|
113
|
+
if (req.query)
|
|
114
|
+
params.push(...args.CreateArgumentsList(req.query));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let controller = DependecyService_1.default.ResolveCtor(empty.constructor);
|
|
118
|
+
controller.Request = req;
|
|
119
|
+
controller.Response = resp;
|
|
120
|
+
controller[method](...params);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
35
124
|
}
|
|
36
125
|
exports.default = Application;
|
|
37
126
|
//# sourceMappingURL=Application.js.map
|
package/dist/Application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../Application.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Application.js","sourceRoot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,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;qBAC1D;iBACJ;gBAED,IAAI,UAAU,GAAG,0BAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,CAAgB,CAAC;gBAChF,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC;gBACzB,UAAU,CAAC,QAAQ,GAAG,IAAI,CAAC;gBAC1B,UAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAA;SACL;IAEL,CAAC;CAMJ;AAhJD,8BAgJC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import IController from "../../interfaces/IController";
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
import IApplication from "../../interfaces/IApplication";
|
|
4
3
|
export declare class ControllerBase implements IController {
|
|
5
4
|
Request: Request;
|
|
6
5
|
Response: Response;
|
|
@@ -10,7 +9,4 @@ export declare class ControllerBase implements IController {
|
|
|
10
9
|
BadRequest<T>(result: T): void;
|
|
11
10
|
Error<T>(result: T): void;
|
|
12
11
|
SendResponse<T>(status: number, result: T): void;
|
|
13
|
-
static AppendController<T extends IController>(ctor: {
|
|
14
|
-
new (...args: any[]): T;
|
|
15
|
-
}, application: IApplication): void;
|
|
16
12
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ControllerBase = void 0;
|
|
7
|
-
const ControllerDecorators_1 = __importDefault(require("../../decorators/controllers/ControllerDecorators"));
|
|
8
|
-
const DependecyService_1 = __importDefault(require("../../dependencyInjection/DependecyService"));
|
|
9
|
-
const HttpVerbs_1 = require("../../enums/httpVerbs/HttpVerbs");
|
|
10
4
|
class ControllerBase {
|
|
11
5
|
constructor() {
|
|
12
6
|
this.Request = {};
|
|
@@ -32,48 +26,6 @@ class ControllerBase {
|
|
|
32
26
|
this.Response.status(status);
|
|
33
27
|
this.Response.json(result);
|
|
34
28
|
}
|
|
35
|
-
static AppendController(ctor, application) {
|
|
36
|
-
let empty = new ctor();
|
|
37
|
-
let methods = Reflect.ownKeys(empty.constructor.prototype).filter(m => {
|
|
38
|
-
return typeof empty[m] == "function";
|
|
39
|
-
});
|
|
40
|
-
let route = ControllerDecorators_1.default.GetRoute(empty);
|
|
41
|
-
if (!route)
|
|
42
|
-
return;
|
|
43
|
-
for (let method of methods) {
|
|
44
|
-
let action = ControllerDecorators_1.default.GetAction(empty, method.toString());
|
|
45
|
-
if (!action) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
let verb = ControllerDecorators_1.default.GetVerb(empty, method.toString());
|
|
49
|
-
if (!verb)
|
|
50
|
-
verb = HttpVerbs_1.HTTPVerbs.GET;
|
|
51
|
-
console.debug("appended : ", verb, `${route}${action}`);
|
|
52
|
-
application.Express[verb.toString().toLowerCase()](`${route}${action}`, (req, resp) => {
|
|
53
|
-
let midlewares = ControllerDecorators_1.default.GetMidlewares(empty).reverse();
|
|
54
|
-
midlewares.push(...ControllerDecorators_1.default.GetBefores(empty, method.toString()).reverse());
|
|
55
|
-
if (midlewares) {
|
|
56
|
-
for (let method of midlewares) {
|
|
57
|
-
method(req);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
let args = ControllerDecorators_1.default.GetArgumentsHandler(empty, method.toString());
|
|
61
|
-
let params = [];
|
|
62
|
-
if (args) {
|
|
63
|
-
if (args.Arguments.length > 0) {
|
|
64
|
-
if (req.body && verb == (HttpVerbs_1.HTTPVerbs.POST || verb == HttpVerbs_1.HTTPVerbs.PUT))
|
|
65
|
-
params = args.CreateArgumentsList(req.body);
|
|
66
|
-
if (req.query)
|
|
67
|
-
params.push(...args.CreateArgumentsList(req.query));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
let controller = DependecyService_1.default.ResolveCtor(empty.constructor);
|
|
71
|
-
controller.Request = req;
|
|
72
|
-
controller.Response = resp;
|
|
73
|
-
controller[method](...params);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
29
|
}
|
|
78
30
|
exports.ControllerBase = ControllerBase;
|
|
79
31
|
//# sourceMappingURL=ControllerBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ControllerBase.js","sourceRoot":"","sources":["../../../controllers/base/ControllerBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ControllerBase.js","sourceRoot":"","sources":["../../../controllers/base/ControllerBase.ts"],"names":[],"mappings":";;;AAKA,MAAa,cAAc;IAKvB;QAHA,YAAO,GAAa,EAAa,CAAC;QAClC,aAAQ,GAAc,EAAc,CAAC;IAKrC,CAAC;IAEM,EAAE,CAAI,MAAU;QAEnB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,OAAO;QAEV,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;IAEM,UAAU,CAAI,MAAU;QAE3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAI,MAAU;QAEtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,YAAY,CAAI,MAAe,EAAE,MAAU;QAE9C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CAEJ;AAxCD,wCAwCC"}
|
|
@@ -3,5 +3,5 @@ import IApplicationConfiguration from './IApplicationConfiguration';
|
|
|
3
3
|
export default interface IApplication {
|
|
4
4
|
Express: Express;
|
|
5
5
|
StartAsync(): Promise<void>;
|
|
6
|
-
|
|
6
|
+
ConfigureAsync(appConfig: IApplicationConfiguration): Promise<void>;
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "web_api_base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "web api base",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"run:tests": "npx jest"
|
|
15
15
|
},
|
|
16
16
|
"author": "adriano.marino1992@gmail.com",
|
|
17
|
+
"repository": "https://github.com/adrianomarino1992/web_api_base.git",
|
|
17
18
|
"license": "ISC",
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@types/express": "^4.17.15",
|
package/readme.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# WEB_API_BASE
|
|
2
|
+
|
|
3
|
+
web_api_base is a npm packaged that allows to create web-apis like MVC of .NET
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install web_api_base
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
First of all we need implement the abstract class __Application__.
|
|
17
|
+
After that, we need to create some controllers and, they must inherit the abstract class __ControllerBase__.
|
|
18
|
+
|
|
19
|
+
### SampleController.ts
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
|
|
23
|
+
import { ControllerBase, ControllersDecorators as CD, HTTPVerbs as verbs } from "web_api_base";
|
|
24
|
+
|
|
25
|
+
@CD.Route("/sample")
|
|
26
|
+
export default class SampleController extends ControllerBase
|
|
27
|
+
{
|
|
28
|
+
@CD.Verb(verbs.GET)
|
|
29
|
+
@CD.Action("/hello")
|
|
30
|
+
public Hello() : void
|
|
31
|
+
{
|
|
32
|
+
this.OK({message: "Hello Word!"})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### App.ts
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import SampleController from "./controllers/SampleController ";
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
import { ControllerBase, Application, IApplicationConfiguration, DependecyService } from "web_api_base";
|
|
45
|
+
|
|
46
|
+
export default class App extends Application
|
|
47
|
+
{
|
|
48
|
+
|
|
49
|
+
public override Configure(appConfig: IApplicationConfiguration): void
|
|
50
|
+
{
|
|
51
|
+
appConfig.Host = "0.0.0.0";
|
|
52
|
+
appConfig.Port = 5555;
|
|
53
|
+
|
|
54
|
+
//allow CORS
|
|
55
|
+
this.UseCors();
|
|
56
|
+
|
|
57
|
+
//register in DI service
|
|
58
|
+
DependecyService.Register(SampleController);
|
|
59
|
+
|
|
60
|
+
//append the controller in the pipe line of requests
|
|
61
|
+
ControllerBase.AppendController(SampleController,this);
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Index.ts
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import Application from './Application';
|
|
71
|
+
|
|
72
|
+
new Application().StartAsync();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Contributing
|
|
78
|
+
|
|
79
|
+
Pull requests are welcome. For major changes, please open an issue first
|
|
80
|
+
to discuss what you would like to change.
|
|
81
|
+
|
|
82
|
+
Please make sure to update tests as appropriate.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|