damex 2.0.12 → 2.0.13
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/classes/AppRouter.d.ts +4 -0
- package/classes/AppRouter.js +12 -0
- package/classes/AppRouter.js.map +1 -0
- package/classes/Injector.d.ts +3 -0
- package/classes/Injector.js +24 -0
- package/classes/Injector.js.map +1 -0
- package/classes/Server.d.ts +10 -0
- package/classes/Server.js +32 -0
- package/classes/Server.js.map +1 -0
- package/classes/index.js +20 -0
- package/classes/index.js.map +1 -0
- package/decorators/controller.decorator.d.ts +1 -0
- package/decorators/controller.decorator.js +34 -0
- package/decorators/controller.decorator.js.map +1 -0
- package/decorators/global-middleware.decorator.d.ts +2 -0
- package/decorators/global-middleware.decorator.js +10 -0
- package/decorators/global-middleware.decorator.js.map +1 -0
- package/decorators/http-methods.decorator.d.ts +5 -0
- package/decorators/http-methods.decorator.js +18 -0
- package/decorators/http-methods.decorator.js.map +1 -0
- package/decorators/index.js +22 -0
- package/decorators/index.js.map +1 -0
- package/decorators/inject.decorator.d.ts +1 -0
- package/decorators/inject.decorator.js +7 -0
- package/decorators/inject.decorator.js.map +1 -0
- package/decorators/middleware.decorator.d.ts +2 -0
- package/decorators/middleware.decorator.js +10 -0
- package/decorators/middleware.decorator.js.map +1 -0
- package/{src/index.ts → index.d.ts} +0 -1
- package/index.js +21 -0
- package/index.js.map +1 -0
- package/package.json +2 -2
- package/types/enums/ControllerMethodsParams.d.ts +6 -0
- package/types/enums/ControllerMethodsParams.js +11 -0
- package/types/enums/ControllerMethodsParams.js.map +1 -0
- package/types/enums/Design.d.ts +3 -0
- package/types/enums/Design.js +8 -0
- package/types/enums/Design.js.map +1 -0
- package/types/enums/HttpMethods.d.ts +7 -0
- package/types/enums/HttpMethods.js +12 -0
- package/types/enums/HttpMethods.js.map +1 -0
- package/types/enums/ServerConfigsParams.d.ts +5 -0
- package/types/enums/ServerConfigsParams.js +10 -0
- package/types/enums/ServerConfigsParams.js.map +1 -0
- package/types/enums/index.js +20 -0
- package/types/enums/index.js.map +1 -0
- package/types/index.js +18 -0
- package/types/index.js.map +1 -0
- package/.prettierrc +0 -5
- package/__tests__/dependency-injection.ts +0 -41
- package/__tests__/server.ts +0 -20
- package/build.js +0 -54
- package/jest.config.js +0 -11
- package/src/classes/AppRouter.ts +0 -9
- package/src/classes/Injector.ts +0 -29
- package/src/classes/Server.ts +0 -44
- package/src/decorators/controller.decorator.ts +0 -62
- package/src/decorators/global-middleware.decorator.ts +0 -12
- package/src/decorators/http-methods.decorator.ts +0 -26
- package/src/decorators/inject.decorator.ts +0 -3
- package/src/decorators/middleware.decorator.ts +0 -13
- package/src/types/enums/ControllerMethodsParams.ts +0 -6
- package/src/types/enums/Design.ts +0 -3
- package/src/types/enums/HttpMethods.ts +0 -7
- package/src/types/enums/ServerConfigsParams.ts +0 -5
- package/tsconfig.json +0 -18
- /package/{src/classes/index.ts → classes/index.d.ts} +0 -0
- /package/{src/decorators/index.ts → decorators/index.d.ts} +0 -0
- /package/{src/types/enums/index.ts → types/enums/index.d.ts} +0 -0
- /package/{src/types/index.ts → types/index.d.ts} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppRouter = void 0;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
class AppRouter {
|
|
6
|
+
static get router() {
|
|
7
|
+
return AppRouter.instance;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.AppRouter = AppRouter;
|
|
11
|
+
AppRouter.instance = (0, express_1.Router)();
|
|
12
|
+
//# sourceMappingURL=AppRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppRouter.js","sourceRoot":"","sources":["../../src/classes/AppRouter.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAEjC,MAAa,SAAS;IAGlB,MAAM,KAAK,MAAM;QACb,OAAO,SAAS,CAAC,QAAQ,CAAC;IAC9B,CAAC;;AALL,8BAMC;AALkB,kBAAQ,GAAG,IAAA,gBAAM,GAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Injector = void 0;
|
|
4
|
+
const Design_1 = require("../types/enums/Design");
|
|
5
|
+
class Injector {
|
|
6
|
+
static inject(target) {
|
|
7
|
+
const params = Reflect.getMetadata(Design_1.Design.ParamTypes, target);
|
|
8
|
+
if (!params) {
|
|
9
|
+
return new target();
|
|
10
|
+
}
|
|
11
|
+
const paramsInstances = [];
|
|
12
|
+
for (let i = 0; params.length > i; i++) {
|
|
13
|
+
const hasParams = !!Reflect.getMetadata(Design_1.Design.ParamTypes, params[i]);
|
|
14
|
+
if (!hasParams) {
|
|
15
|
+
paramsInstances.push(new params[i]());
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
paramsInstances.push(Injector.inject(params[i]));
|
|
19
|
+
}
|
|
20
|
+
return new target(...paramsInstances);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Injector = Injector;
|
|
24
|
+
//# sourceMappingURL=Injector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Injector.js","sourceRoot":"","sources":["../../src/classes/Injector.ts"],"names":[],"mappings":";;;AAAA,kDAA+C;AAE/C,MAAa,QAAQ;IACjB,MAAM,CAAC,MAAM,CAAC,MAAW;QACrB,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,eAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAE9D,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,IAAI,MAAM,EAAE,CAAC;QACxB,CAAC;QAED,MAAM,eAAe,GAAe,EAAE,CAAC;QAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,CACnC,eAAM,CAAC,UAAU,EACjB,MAAM,CAAC,CAAC,CAAC,CACZ,CAAC;YAEF,IAAI,CAAC,SAAS,EAAE,CAAC;gBACb,eAAe,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACtC,SAAS;YACb,CAAC;YAED,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC;IAC1C,CAAC;CACJ;AA1BD,4BA0BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express, { type RequestHandler } from 'express';
|
|
2
|
+
type HttpClient = express.Application;
|
|
3
|
+
export declare class Server {
|
|
4
|
+
private readonly app;
|
|
5
|
+
constructor(app: HttpClient);
|
|
6
|
+
start(port?: number): void;
|
|
7
|
+
use(...handlers: RequestHandler[]): void;
|
|
8
|
+
private setupControllers;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Server = void 0;
|
|
7
|
+
const enums_1 = require("../types/enums");
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
class Server {
|
|
10
|
+
constructor(app) {
|
|
11
|
+
this.app = app;
|
|
12
|
+
this.setupControllers(this.app);
|
|
13
|
+
}
|
|
14
|
+
start(port = 3000) {
|
|
15
|
+
this.app.listen(port, () => {
|
|
16
|
+
console.log(`Application running on port ${port} 🟢`);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
use(...handlers) {
|
|
20
|
+
this.app.use(handlers);
|
|
21
|
+
}
|
|
22
|
+
setupControllers(app) {
|
|
23
|
+
const controllers = Reflect.getMetadata(enums_1.ServerConfigsParams.Controllers, Server);
|
|
24
|
+
app.use(express_1.default.json());
|
|
25
|
+
controllers.forEach((controller) => {
|
|
26
|
+
const router = Reflect.getMetadata(enums_1.ServerConfigsParams.Router, controller);
|
|
27
|
+
app.use(router);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Server = Server;
|
|
32
|
+
//# sourceMappingURL=Server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../src/classes/Server.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAqD;AACrD,sDAIiB;AAIjB,MAAa,MAAM;IAGf,YAAY,GAAe;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAe,IAAI;QACrB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACvB,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,KAAK,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACP,CAAC;IAED,GAAG,CAAC,GAAG,QAA0B;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;IAEO,gBAAgB,CAAC,GAAe;QACpC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CACnC,2BAAmB,CAAC,WAAW,EAC/B,MAAM,CACT,CAAC;QAEF,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAExB,WAAW,CAAC,OAAO,CAAC,CAAC,UAAe,EAAE,EAAE;YACpC,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAC9B,2BAAmB,CAAC,MAAM,EAC1B,UAAU,CACb,CAAC;YACF,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAlCD,wBAkCC"}
|
package/classes/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AppRouter"), exports);
|
|
18
|
+
__exportStar(require("./Server"), exports);
|
|
19
|
+
__exportStar(require("./Injector"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB;AACzB,6CAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Controller(path: string): (target: any) => any;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Controller = Controller;
|
|
4
|
+
const classes_1 = require("../classes");
|
|
5
|
+
const AppRouter_1 = require("../classes/AppRouter");
|
|
6
|
+
const enums_1 = require("../types/enums");
|
|
7
|
+
const ServerConfigsParams_1 = require("../types/enums/ServerConfigsParams");
|
|
8
|
+
function Controller(path) {
|
|
9
|
+
const router = AppRouter_1.AppRouter.router;
|
|
10
|
+
return function (target) {
|
|
11
|
+
const instance = classes_1.Injector.inject(target);
|
|
12
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
13
|
+
const [, ..._actionsNames] = Object.getOwnPropertyNames(prototype);
|
|
14
|
+
_actionsNames.forEach((_actionName) => {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
const _method = (_a = Reflect.getOwnMetadata(_actionName, prototype, enums_1.ControllerMethodsParams.Method)) !== null && _a !== void 0 ? _a : '';
|
|
17
|
+
const controllerGlobalMiddleware = Reflect.getMetadata(ServerConfigsParams_1.ServerConfigsParams.GlobalMiddleware, target);
|
|
18
|
+
const _middlewares = (_b = Reflect.getOwnMetadata(_actionName, prototype, enums_1.ControllerMethodsParams.Middleware)) !== null && _b !== void 0 ? _b : [];
|
|
19
|
+
const _path = (_c = Reflect.getOwnMetadata(_actionName, prototype, enums_1.ControllerMethodsParams.Path)) !== null && _c !== void 0 ? _c : '';
|
|
20
|
+
router[_method](`${path}${_path}`, [
|
|
21
|
+
instance[_actionName],
|
|
22
|
+
...controllerGlobalMiddleware,
|
|
23
|
+
..._middlewares,
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
Reflect.defineMetadata(ServerConfigsParams_1.ServerConfigsParams.Router, router, target);
|
|
27
|
+
appendController(target);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function appendController(controller) {
|
|
31
|
+
const prevControllers = Reflect.getMetadata(ServerConfigsParams_1.ServerConfigsParams.Controllers, classes_1.Server) || [];
|
|
32
|
+
Reflect.defineMetadata(ServerConfigsParams_1.ServerConfigsParams.Controllers, [...prevControllers, controller], classes_1.Server);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=controller.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.decorator.js","sourceRoot":"","sources":["../../src/decorators/controller.decorator.ts"],"names":[],"mappings":";;AAKA,gCA6CC;AAlDD,wCAA8C;AAC9C,oDAAiD;AACjD,0CAAyD;AACzD,4EAAyE;AAEzE,SAAgB,UAAU,CAAC,IAAY;IACnC,MAAM,MAAM,GAAQ,qBAAS,CAAC,MAAM,CAAC;IAErC,OAAO,UAAU,MAAW;QACxB,MAAM,QAAQ,GAAG,kBAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAClD,MAAM,CAAC,EAAE,GAAG,aAAa,CAAC,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAEnE,aAAa,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;;YAClC,MAAM,OAAO,GACT,MAAA,OAAO,CAAC,cAAc,CAClB,WAAW,EACX,SAAS,EACT,+BAAuB,CAAC,MAAM,CACjC,mCAAI,EAAE,CAAC;YAEZ,MAAM,0BAA0B,GAAG,OAAO,CAAC,WAAW,CAClD,yCAAmB,CAAC,gBAAgB,EACpC,MAAM,CACT,CAAC;YAEF,MAAM,YAAY,GACd,MAAA,OAAO,CAAC,cAAc,CAClB,WAAW,EACX,SAAS,EACT,+BAAuB,CAAC,UAAU,CACrC,mCAAI,EAAE,CAAC;YAEZ,MAAM,KAAK,GACP,MAAA,OAAO,CAAC,cAAc,CAClB,WAAW,EACX,SAAS,EACT,+BAAuB,CAAC,IAAI,CAC/B,mCAAI,EAAE,CAAC;YAEZ,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,EAAE,EAAE;gBAC/B,QAAQ,CAAC,WAAW,CAAC;gBACrB,GAAG,0BAA0B;gBAC7B,GAAG,YAAY;aAClB,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,CAAC,yCAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;AACN,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAe;IACrC,MAAM,eAAe,GACjB,OAAO,CAAC,WAAW,CAAC,yCAAmB,CAAC,WAAW,EAAE,gBAAM,CAAC,IAAI,EAAE,CAAC;IAEvE,OAAO,CAAC,cAAc,CAClB,yCAAmB,CAAC,WAAW,EAC/B,CAAC,GAAG,eAAe,EAAE,UAAU,CAAC,EAChC,gBAAM,CACT,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalMiddleware = GlobalMiddleware;
|
|
4
|
+
const ServerConfigsParams_1 = require("../types/enums/ServerConfigsParams");
|
|
5
|
+
function GlobalMiddleware(handlers) {
|
|
6
|
+
return function (target) {
|
|
7
|
+
Reflect.defineMetadata(ServerConfigsParams_1.ServerConfigsParams.GlobalMiddleware, handlers, target);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=global-middleware.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-middleware.decorator.js","sourceRoot":"","sources":["../../src/decorators/global-middleware.decorator.ts"],"names":[],"mappings":";;AAGA,4CAQC;AAXD,4EAAyE;AAGzE,SAAgB,gBAAgB,CAAC,QAA0B;IACvD,OAAO,UAAU,MAAW;QACxB,OAAO,CAAC,cAAc,CAClB,yCAAmB,CAAC,gBAAgB,EACpC,QAAQ,EACR,MAAM,CACT,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const Get: (path?: string) => (target: any, propertyKey: any) => any;
|
|
2
|
+
export declare const Post: (path?: string) => (target: any, propertyKey: any) => any;
|
|
3
|
+
export declare const Put: (path?: string) => (target: any, propertyKey: any) => any;
|
|
4
|
+
export declare const Patch: (path?: string) => (target: any, propertyKey: any) => any;
|
|
5
|
+
export declare const Delete: (path?: string) => (target: any, propertyKey: any) => any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0;
|
|
4
|
+
const enums_1 = require("../types/enums");
|
|
5
|
+
function createHttpMethod(method) {
|
|
6
|
+
return function (path) {
|
|
7
|
+
return function (target, propertyKey) {
|
|
8
|
+
Reflect.defineMetadata(propertyKey, method, target, enums_1.ControllerMethodsParams.Method);
|
|
9
|
+
Reflect.defineMetadata(propertyKey, path, target, enums_1.ControllerMethodsParams.Path);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.Get = createHttpMethod(enums_1.HttpMethods.Get);
|
|
14
|
+
exports.Post = createHttpMethod(enums_1.HttpMethods.Post);
|
|
15
|
+
exports.Put = createHttpMethod(enums_1.HttpMethods.Put);
|
|
16
|
+
exports.Patch = createHttpMethod(enums_1.HttpMethods.Patch);
|
|
17
|
+
exports.Delete = createHttpMethod(enums_1.HttpMethods.Delete);
|
|
18
|
+
//# sourceMappingURL=http-methods.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-methods.decorator.js","sourceRoot":"","sources":["../../src/decorators/http-methods.decorator.ts"],"names":[],"mappings":";;;AAAA,0CAAsE;AAEtE,SAAS,gBAAgB,CAAC,MAAmB;IACzC,OAAO,UAAU,IAAa;QAC1B,OAAO,UAAU,MAAW,EAAE,WAAgB;YAC1C,OAAO,CAAC,cAAc,CAClB,WAAW,EACX,MAAM,EACN,MAAM,EACN,+BAAuB,CAAC,MAAM,CACjC,CAAC;YACF,OAAO,CAAC,cAAc,CAClB,WAAW,EACX,IAAI,EACJ,MAAM,EACN,+BAAuB,CAAC,IAAI,CAC/B,CAAC;QACN,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AAEY,QAAA,GAAG,GAAG,gBAAgB,CAAC,mBAAW,CAAC,GAAG,CAAC,CAAC;AACxC,QAAA,IAAI,GAAG,gBAAgB,CAAC,mBAAW,CAAC,IAAI,CAAC,CAAC;AAC1C,QAAA,GAAG,GAAG,gBAAgB,CAAC,mBAAW,CAAC,GAAG,CAAC,CAAC;AACxC,QAAA,KAAK,GAAG,gBAAgB,CAAC,mBAAW,CAAC,KAAK,CAAC,CAAC;AAC5C,QAAA,MAAM,GAAG,gBAAgB,CAAC,mBAAW,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./http-methods.decorator"), exports);
|
|
18
|
+
__exportStar(require("./controller.decorator"), exports);
|
|
19
|
+
__exportStar(require("./middleware.decorator"), exports);
|
|
20
|
+
__exportStar(require("./global-middleware.decorator"), exports);
|
|
21
|
+
__exportStar(require("./inject.decorator"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,yDAAuC;AACvC,yDAAuC;AACvC,gEAA8C;AAC9C,qDAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Inject(): (_target: any) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject.decorator.ts"],"names":[],"mappings":";;AAAA,wBAEC;AAFD,SAAgB,MAAM;IAClB,OAAO,UAAU,OAAY,IAAG,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Middleware = Middleware;
|
|
4
|
+
const enums_1 = require("../types/enums");
|
|
5
|
+
function Middleware(handlers) {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
Reflect.defineMetadata(propertyKey, handlers, target, enums_1.ControllerMethodsParams.Middleware);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=middleware.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.decorator.js","sourceRoot":"","sources":["../../src/decorators/middleware.decorator.ts"],"names":[],"mappings":";;AAGA,gCASC;AAZD,0CAAyD;AAGzD,SAAgB,UAAU,CAAC,QAA0B;IACjD,OAAO,UAAU,MAAW,EAAE,WAAgB;QAC1C,OAAO,CAAC,cAAc,CAClB,WAAW,EACX,QAAQ,EACR,MAAM,EACN,+BAAuB,CAAC,UAAU,CACrC,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
require("reflect-metadata");
|
|
18
|
+
__exportStar(require("./classes"), exports);
|
|
19
|
+
__exportStar(require("./decorators"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAA0B;AAE1B,4CAA0B;AAC1B,+CAA6B;AAC7B,0CAAwB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "damex",
|
|
3
3
|
"module": "./index.js",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.13",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "matusalem.dev@gmail.com",
|
|
7
7
|
"name": "Matusal3m",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"test": "jest",
|
|
16
|
-
"build": "node build.js && tsc
|
|
16
|
+
"build": "node build.js && tsc"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/cors": "^2.8.17",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControllerMethodsParams = void 0;
|
|
4
|
+
var ControllerMethodsParams;
|
|
5
|
+
(function (ControllerMethodsParams) {
|
|
6
|
+
ControllerMethodsParams["Path"] = "path";
|
|
7
|
+
ControllerMethodsParams["Method"] = "method";
|
|
8
|
+
ControllerMethodsParams["Middleware"] = "middleware";
|
|
9
|
+
ControllerMethodsParams["Router"] = "router";
|
|
10
|
+
})(ControllerMethodsParams || (exports.ControllerMethodsParams = ControllerMethodsParams = {}));
|
|
11
|
+
//# sourceMappingURL=ControllerMethodsParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControllerMethodsParams.js","sourceRoot":"","sources":["../../../src/types/enums/ControllerMethodsParams.ts"],"names":[],"mappings":";;;AAAA,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,wCAAa,CAAA;IACb,4CAAiB,CAAA;IACjB,oDAAyB,CAAA;IACzB,4CAAiB,CAAA;AACrB,CAAC,EALW,uBAAuB,uCAAvB,uBAAuB,QAKlC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Design = void 0;
|
|
4
|
+
var Design;
|
|
5
|
+
(function (Design) {
|
|
6
|
+
Design["ParamTypes"] = "design:paramtypes";
|
|
7
|
+
})(Design || (exports.Design = Design = {}));
|
|
8
|
+
//# sourceMappingURL=Design.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Design.js","sourceRoot":"","sources":["../../../src/types/enums/Design.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAEX;AAFD,WAAY,MAAM;IACd,0CAAgC,CAAA;AACpC,CAAC,EAFW,MAAM,sBAAN,MAAM,QAEjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = void 0;
|
|
4
|
+
var HttpMethods;
|
|
5
|
+
(function (HttpMethods) {
|
|
6
|
+
HttpMethods["Get"] = "get";
|
|
7
|
+
HttpMethods["Post"] = "post";
|
|
8
|
+
HttpMethods["Put"] = "put";
|
|
9
|
+
HttpMethods["Patch"] = "patch";
|
|
10
|
+
HttpMethods["Delete"] = "delete";
|
|
11
|
+
})(HttpMethods || (exports.HttpMethods = HttpMethods = {}));
|
|
12
|
+
//# sourceMappingURL=HttpMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpMethods.js","sourceRoot":"","sources":["../../../src/types/enums/HttpMethods.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAMX;AAND,WAAY,WAAW;IACnB,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,0BAAW,CAAA;IACX,8BAAe,CAAA;IACf,gCAAiB,CAAA;AACrB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerConfigsParams = void 0;
|
|
4
|
+
var ServerConfigsParams;
|
|
5
|
+
(function (ServerConfigsParams) {
|
|
6
|
+
ServerConfigsParams["Router"] = "router";
|
|
7
|
+
ServerConfigsParams["GlobalMiddleware"] = "globalMiddleware";
|
|
8
|
+
ServerConfigsParams["Controllers"] = "controllers";
|
|
9
|
+
})(ServerConfigsParams || (exports.ServerConfigsParams = ServerConfigsParams = {}));
|
|
10
|
+
//# sourceMappingURL=ServerConfigsParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerConfigsParams.js","sourceRoot":"","sources":["../../../src/types/enums/ServerConfigsParams.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,wCAAiB,CAAA;IACjB,4DAAqC,CAAA;IACrC,kDAA2B,CAAA;AAC/B,CAAC,EAJW,mBAAmB,mCAAnB,mBAAmB,QAI9B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ControllerMethodsParams"), exports);
|
|
18
|
+
__exportStar(require("./HttpMethods"), exports);
|
|
19
|
+
__exportStar(require("./ServerConfigsParams"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/enums/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,gDAA8B;AAC9B,wDAAsC"}
|
package/types/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./enums"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
|
package/.prettierrc
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Injector } from '../src';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import { Inject } from '../src/decorators/inject.decorator';
|
|
4
|
-
|
|
5
|
-
class Foo {
|
|
6
|
-
foo() {
|
|
7
|
-
console.log('foo');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@Inject()
|
|
12
|
-
class Bar {
|
|
13
|
-
constructor(private foo: Foo) {}
|
|
14
|
-
|
|
15
|
-
callFoo() {
|
|
16
|
-
this.foo.foo();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Inject()
|
|
21
|
-
class FooBar {
|
|
22
|
-
constructor(
|
|
23
|
-
private foo: Foo,
|
|
24
|
-
private bar: Bar,
|
|
25
|
-
) {}
|
|
26
|
-
|
|
27
|
-
fooBar() {
|
|
28
|
-
console.log('fooBar');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('dependency injection', () => {
|
|
33
|
-
test('inject Foo into Bar', () => {
|
|
34
|
-
expect(Injector.inject(Bar).callFoo).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('inject Foo and Bar into FooBar', () => {
|
|
38
|
-
const fooBar = Injector.inject(FooBar);
|
|
39
|
-
expect(fooBar.fooBar).toBeDefined();
|
|
40
|
-
});
|
|
41
|
-
});
|
package/__tests__/server.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import { Controller, Get, GlobalMiddleware, Middleware, Server } from '../src';
|
|
3
|
-
|
|
4
|
-
function handle(_req: Request, _res: Response, next: NextFunction) {
|
|
5
|
-
next();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
@Controller('')
|
|
9
|
-
@GlobalMiddleware([handle])
|
|
10
|
-
export class MyController {
|
|
11
|
-
constructor() {}
|
|
12
|
-
|
|
13
|
-
@Get('')
|
|
14
|
-
@Middleware([handle])
|
|
15
|
-
async help(req: Request, res: Response) {
|
|
16
|
-
res.send('<div>oiiii</div>');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
new Server().start(3333);
|
package/build.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { cp, mkdir, readFile } from 'fs/promises';
|
|
4
|
-
import { stdin as input, stdout as output } from 'process';
|
|
5
|
-
import { createInterface } from 'readline/promises';
|
|
6
|
-
|
|
7
|
-
const rl = createInterface({ input, output });
|
|
8
|
-
|
|
9
|
-
const distPath = './dist';
|
|
10
|
-
const packageJsonPath = './package.json';
|
|
11
|
-
const readmePath = './README.md';
|
|
12
|
-
|
|
13
|
-
async function getPackageVersion() {
|
|
14
|
-
const packageContent = await readFile(packageJsonPath, {
|
|
15
|
-
encoding: 'utf8',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const regex = /"version"\s*:\s*"([^"]+)"/gm;
|
|
19
|
-
const version = regex.exec(packageContent);
|
|
20
|
-
|
|
21
|
-
return version[1];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function confirmVersionLoop() {
|
|
25
|
-
let answer = '';
|
|
26
|
-
while (true) {
|
|
27
|
-
answer = await rl.question(
|
|
28
|
-
`\n --- Have you updated the package version(y,n)? \n --- Current version is ${await getPackageVersion()}: `,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
answer.toLowerCase();
|
|
32
|
-
|
|
33
|
-
if (answer == 'n') {
|
|
34
|
-
console.log('Update the current version');
|
|
35
|
-
process.exit(-1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
rl.close();
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
(async () => {
|
|
44
|
-
await confirmVersionLoop();
|
|
45
|
-
|
|
46
|
-
if (existsSync(distPath)) {
|
|
47
|
-
execSync(`rm -rf ${distPath}`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
await mkdir(distPath);
|
|
51
|
-
|
|
52
|
-
await cp(packageJsonPath, `${distPath}/package.json`);
|
|
53
|
-
await cp(readmePath, `${distPath}/README.md`);
|
|
54
|
-
})();
|
package/jest.config.js
DELETED
package/src/classes/AppRouter.ts
DELETED
package/src/classes/Injector.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Design } from '../types/enums/Design';
|
|
2
|
-
|
|
3
|
-
export class Injector {
|
|
4
|
-
static inject(target: any): any {
|
|
5
|
-
const params = Reflect.getMetadata(Design.ParamTypes, target);
|
|
6
|
-
|
|
7
|
-
if (!params) {
|
|
8
|
-
return new target();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const paramsInstances: Array<any> = [];
|
|
12
|
-
|
|
13
|
-
for (let i = 0; params.length > i; i++) {
|
|
14
|
-
const hasParams = !!Reflect.getMetadata(
|
|
15
|
-
Design.ParamTypes,
|
|
16
|
-
params[i],
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
if (!hasParams) {
|
|
20
|
-
paramsInstances.push(new params[i]());
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
paramsInstances.push(Injector.inject(params[i]));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return new target(...paramsInstances);
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/classes/Server.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ServerConfigsParams } from '../types/enums';
|
|
2
|
-
import express, {
|
|
3
|
-
type Express,
|
|
4
|
-
type Application,
|
|
5
|
-
type RequestHandler,
|
|
6
|
-
} from 'express';
|
|
7
|
-
|
|
8
|
-
type HttpClient = express.Application;
|
|
9
|
-
|
|
10
|
-
export class Server {
|
|
11
|
-
private readonly app: HttpClient;
|
|
12
|
-
|
|
13
|
-
constructor(app: HttpClient) {
|
|
14
|
-
this.app = app;
|
|
15
|
-
this.setupControllers(this.app);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
start(port: number = 3000) {
|
|
19
|
-
this.app.listen(port, () => {
|
|
20
|
-
console.log(`Application running on port ${port} 🟢`);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
use(...handlers: RequestHandler[]) {
|
|
25
|
-
this.app.use(handlers);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private setupControllers(app: HttpClient) {
|
|
29
|
-
const controllers = Reflect.getMetadata(
|
|
30
|
-
ServerConfigsParams.Controllers,
|
|
31
|
-
Server,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
app.use(express.json());
|
|
35
|
-
|
|
36
|
-
controllers.forEach((controller: any) => {
|
|
37
|
-
const router = Reflect.getMetadata(
|
|
38
|
-
ServerConfigsParams.Router,
|
|
39
|
-
controller,
|
|
40
|
-
);
|
|
41
|
-
app.use(router);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Injector, Server } from '../classes';
|
|
2
|
-
import { AppRouter } from '../classes/AppRouter';
|
|
3
|
-
import { ControllerMethodsParams } from '../types/enums';
|
|
4
|
-
import { ServerConfigsParams } from '../types/enums/ServerConfigsParams';
|
|
5
|
-
|
|
6
|
-
export function Controller(path: string) {
|
|
7
|
-
const router: any = AppRouter.router;
|
|
8
|
-
|
|
9
|
-
return function (target: any): any {
|
|
10
|
-
const instance = Injector.inject(target);
|
|
11
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
12
|
-
const [, ..._actionsNames] = Object.getOwnPropertyNames(prototype);
|
|
13
|
-
|
|
14
|
-
_actionsNames.forEach((_actionName) => {
|
|
15
|
-
const _method =
|
|
16
|
-
Reflect.getOwnMetadata(
|
|
17
|
-
_actionName,
|
|
18
|
-
prototype,
|
|
19
|
-
ControllerMethodsParams.Method,
|
|
20
|
-
) ?? '';
|
|
21
|
-
|
|
22
|
-
const controllerGlobalMiddleware = Reflect.getMetadata(
|
|
23
|
-
ServerConfigsParams.GlobalMiddleware,
|
|
24
|
-
target,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const _middlewares =
|
|
28
|
-
Reflect.getOwnMetadata(
|
|
29
|
-
_actionName,
|
|
30
|
-
prototype,
|
|
31
|
-
ControllerMethodsParams.Middleware,
|
|
32
|
-
) ?? [];
|
|
33
|
-
|
|
34
|
-
const _path =
|
|
35
|
-
Reflect.getOwnMetadata(
|
|
36
|
-
_actionName,
|
|
37
|
-
prototype,
|
|
38
|
-
ControllerMethodsParams.Path,
|
|
39
|
-
) ?? '';
|
|
40
|
-
|
|
41
|
-
router[_method](`${path}${_path}`, [
|
|
42
|
-
instance[_actionName],
|
|
43
|
-
...controllerGlobalMiddleware,
|
|
44
|
-
..._middlewares,
|
|
45
|
-
]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
Reflect.defineMetadata(ServerConfigsParams.Router, router, target);
|
|
49
|
-
appendController(target);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function appendController(controller: any) {
|
|
54
|
-
const prevControllers =
|
|
55
|
-
Reflect.getMetadata(ServerConfigsParams.Controllers, Server) || [];
|
|
56
|
-
|
|
57
|
-
Reflect.defineMetadata(
|
|
58
|
-
ServerConfigsParams.Controllers,
|
|
59
|
-
[...prevControllers, controller],
|
|
60
|
-
Server,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ServerConfigsParams } from '../types/enums/ServerConfigsParams';
|
|
2
|
-
import type { RequestHandler } from 'express';
|
|
3
|
-
|
|
4
|
-
export function GlobalMiddleware(handlers: RequestHandler[]) {
|
|
5
|
-
return function (target: any): void {
|
|
6
|
-
Reflect.defineMetadata(
|
|
7
|
-
ServerConfigsParams.GlobalMiddleware,
|
|
8
|
-
handlers,
|
|
9
|
-
target,
|
|
10
|
-
);
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ControllerMethodsParams, HttpMethods } from '../types/enums';
|
|
2
|
-
|
|
3
|
-
function createHttpMethod(method: HttpMethods) {
|
|
4
|
-
return function (path?: string) {
|
|
5
|
-
return function (target: any, propertyKey: any): any {
|
|
6
|
-
Reflect.defineMetadata(
|
|
7
|
-
propertyKey,
|
|
8
|
-
method,
|
|
9
|
-
target,
|
|
10
|
-
ControllerMethodsParams.Method,
|
|
11
|
-
);
|
|
12
|
-
Reflect.defineMetadata(
|
|
13
|
-
propertyKey,
|
|
14
|
-
path,
|
|
15
|
-
target,
|
|
16
|
-
ControllerMethodsParams.Path,
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const Get = createHttpMethod(HttpMethods.Get);
|
|
23
|
-
export const Post = createHttpMethod(HttpMethods.Post);
|
|
24
|
-
export const Put = createHttpMethod(HttpMethods.Put);
|
|
25
|
-
export const Patch = createHttpMethod(HttpMethods.Patch);
|
|
26
|
-
export const Delete = createHttpMethod(HttpMethods.Delete);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ControllerMethodsParams } from '../types/enums';
|
|
2
|
-
import type { RequestHandler } from 'express';
|
|
3
|
-
|
|
4
|
-
export function Middleware(handlers: RequestHandler[]) {
|
|
5
|
-
return function (target: any, propertyKey: any): any {
|
|
6
|
-
Reflect.defineMetadata(
|
|
7
|
-
propertyKey,
|
|
8
|
-
handlers,
|
|
9
|
-
target,
|
|
10
|
-
ControllerMethodsParams.Middleware,
|
|
11
|
-
);
|
|
12
|
-
};
|
|
13
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2016",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"typeRoots": ["src/types/*", "node_modules/@types"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"removeComments": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"experimentalDecorators": true,
|
|
15
|
-
"emitDecoratorMetadata": true
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*"]
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|