damex 2.0.13 → 2.0.15

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.
Files changed (59) hide show
  1. package/README.md +8 -51
  2. package/package.json +15 -28
  3. package/src/consts.ts +6 -0
  4. package/src/decorators.ts +75 -0
  5. package/src/di.ts +29 -0
  6. package/src/http-core.ts +127 -0
  7. package/src/index.ts +5 -0
  8. package/tsconfig.json +28 -0
  9. package/classes/AppRouter.d.ts +0 -4
  10. package/classes/AppRouter.js +0 -12
  11. package/classes/AppRouter.js.map +0 -1
  12. package/classes/Injector.d.ts +0 -3
  13. package/classes/Injector.js +0 -24
  14. package/classes/Injector.js.map +0 -1
  15. package/classes/Server.d.ts +0 -10
  16. package/classes/Server.js +0 -32
  17. package/classes/Server.js.map +0 -1
  18. package/classes/index.d.ts +0 -3
  19. package/classes/index.js +0 -20
  20. package/classes/index.js.map +0 -1
  21. package/decorators/controller.decorator.d.ts +0 -1
  22. package/decorators/controller.decorator.js +0 -34
  23. package/decorators/controller.decorator.js.map +0 -1
  24. package/decorators/global-middleware.decorator.d.ts +0 -2
  25. package/decorators/global-middleware.decorator.js +0 -10
  26. package/decorators/global-middleware.decorator.js.map +0 -1
  27. package/decorators/http-methods.decorator.d.ts +0 -5
  28. package/decorators/http-methods.decorator.js +0 -18
  29. package/decorators/http-methods.decorator.js.map +0 -1
  30. package/decorators/index.d.ts +0 -5
  31. package/decorators/index.js +0 -22
  32. package/decorators/index.js.map +0 -1
  33. package/decorators/inject.decorator.d.ts +0 -1
  34. package/decorators/inject.decorator.js +0 -7
  35. package/decorators/inject.decorator.js.map +0 -1
  36. package/decorators/middleware.decorator.d.ts +0 -2
  37. package/decorators/middleware.decorator.js +0 -10
  38. package/decorators/middleware.decorator.js.map +0 -1
  39. package/index.d.ts +0 -4
  40. package/index.js +0 -21
  41. package/index.js.map +0 -1
  42. package/types/enums/ControllerMethodsParams.d.ts +0 -6
  43. package/types/enums/ControllerMethodsParams.js +0 -11
  44. package/types/enums/ControllerMethodsParams.js.map +0 -1
  45. package/types/enums/Design.d.ts +0 -3
  46. package/types/enums/Design.js +0 -8
  47. package/types/enums/Design.js.map +0 -1
  48. package/types/enums/HttpMethods.d.ts +0 -7
  49. package/types/enums/HttpMethods.js +0 -12
  50. package/types/enums/HttpMethods.js.map +0 -1
  51. package/types/enums/ServerConfigsParams.d.ts +0 -5
  52. package/types/enums/ServerConfigsParams.js +0 -10
  53. package/types/enums/ServerConfigsParams.js.map +0 -1
  54. package/types/enums/index.d.ts +0 -3
  55. package/types/enums/index.js +0 -20
  56. package/types/enums/index.js.map +0 -1
  57. package/types/index.d.ts +0 -1
  58. package/types/index.js +0 -18
  59. package/types/index.js.map +0 -1
package/README.md CHANGED
@@ -1,58 +1,15 @@
1
- ## Decorators
1
+ # damex
2
2
 
3
- ### Used in Classes
3
+ To install dependencies:
4
4
 
5
- ```typescript
6
- @Controller
5
+ ```bash
6
+ bun install
7
7
  ```
8
8
 
9
- Receives a string indicating the route of the controller.
9
+ To run:
10
10
 
11
- ```typescript
12
- @GlobalMiddleware
11
+ ```bash
12
+ bun run index.ts
13
13
  ```
14
14
 
15
- Receives an array with all the middleware methods that will be applied to all the methods of the controller.
16
-
17
- ```typescript
18
- @Inject
19
- ```
20
-
21
- Used on classes that required DI. If the class Already has a decorator (as @Controller), the @Inject is not required.
22
-
23
- ### Used in Methods
24
-
25
- ```typescript
26
- @Get - path: string
27
- @Post - path: string
28
- @Put - path: string
29
- @Patch - path: string
30
- @Delete - path: string
31
- @Middleware - Array with methods
32
- ```
33
-
34
- #### Example
35
-
36
- ```typescript
37
- @Controller('/users')
38
- @GlobalMiddleware([auth])
39
- export class UsersController {
40
- constructor(private userService: UserService) {}
41
-
42
- @Get()
43
- @Middleware([logger])
44
- async getAll(req: Request, res: Response) {
45
- const users = await this.userService.all();
46
-
47
- res.status(200).send(users);
48
- }
49
-
50
- @Get('/:id')
51
- @Middleware([anotherLogger])
52
- async getById(req: Request, res: Response) {
53
- const users = await this.userService.findById(req.params.id!);
54
-
55
- res.status(200).send(users);
56
- }
57
- }
58
- ```
15
+ This project was created using `bun init` in bun v1.2.8. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
package/package.json CHANGED
@@ -1,30 +1,17 @@
1
1
  {
2
- "name": "damex",
3
- "module": "./index.js",
4
- "version": "2.0.13",
5
- "author": {
6
- "email": "matusalem.dev@gmail.com",
7
- "name": "Matusal3m",
8
- "url": "https://github.com/matusal3m"
9
- },
10
- "main": "./index.js",
11
- "exports": {
12
- ".": "./index.js"
13
- },
14
- "scripts": {
15
- "test": "jest",
16
- "build": "node build.js && tsc"
17
- },
18
- "devDependencies": {
19
- "@types/cors": "^2.8.17",
20
- "@types/express": "^5.0.3",
21
- "@types/jest": "^30.0.0",
22
- "ts-jest": "^29.4.0"
23
- },
24
- "dependencies": {
25
- "cors": "^2.8.5",
26
- "express": "^5.1.0",
27
- "reflect-metadata": "^0.2.2",
28
- "typescript": "^5.8.3"
29
- }
2
+ "name": "damex",
3
+ "version": "2.0.15",
4
+ "module": "src/index.ts",
5
+ "type": "module",
6
+ "devDependencies": {
7
+ "@types/bun": "latest",
8
+ "@types/express": "^5.0.3"
9
+ },
10
+ "peerDependencies": {
11
+ "typescript": "^5"
12
+ },
13
+ "dependencies": {
14
+ "express": "^5.1.0",
15
+ "reflect-metadata": "^0.2.2"
16
+ }
30
17
  }
package/src/consts.ts ADDED
@@ -0,0 +1,6 @@
1
+ export const CONTROLLER_METHOD = "controller:method";
2
+ export const CONTROLLER_PATH = "controller:path";
3
+ export const CONTROLLER_CLASS_MIDDLEWARE = "controller:class_middleware";
4
+ export const CONTROLLER_MIDDLEWARE = "controller:middleware";
5
+ export const SERVER_CONTROLLERS = "server:controllers";
6
+ export const SERVER_ROUTER = "server:router";
@@ -0,0 +1,75 @@
1
+ import type { RequestHandler } from "express";
2
+ import {
3
+ CONTROLLER_METHOD,
4
+ CONTROLLER_PATH,
5
+ CONTROLLER_CLASS_MIDDLEWARE,
6
+ CONTROLLER_MIDDLEWARE,
7
+ } from "./consts";
8
+ import { AppRouter, ControllerActionReader, Server } from "./http-core";
9
+ import { DI } from "./di";
10
+
11
+ export function Controller(controllerPath?: string) {
12
+ const router = AppRouter.get();
13
+
14
+ return (target: any): any => {
15
+ const instance = DI.new(target);
16
+ const prototype = Object.getPrototypeOf(target);
17
+ const [, ...actionsNames] = Object.getOwnPropertyNames(prototype);
18
+
19
+ actionsNames.forEach((action) => {
20
+ const controllerActionReader = new ControllerActionReader(
21
+ action,
22
+ prototype,
23
+ target,
24
+ );
25
+
26
+ const actionPath = controllerActionReader.getPath();
27
+ const method = controllerActionReader.getMethod();
28
+ const middlewares = controllerActionReader.getMiddlewares();
29
+ const classMiddleware =
30
+ controllerActionReader.getControllerClassMiddleware();
31
+
32
+ // @ts-ignore
33
+ router[method](
34
+ `${controllerPath}/${actionPath}`,
35
+ ...middlewares,
36
+ ...classMiddleware,
37
+ instance[action],
38
+ );
39
+
40
+ Server.appendControllerMetadata(target, router);
41
+ });
42
+ };
43
+ }
44
+
45
+ export function Middleware(handlers: RequestHandler[]) {
46
+ return function (target: any, propertyKey: any): any {
47
+ Reflect.defineMetadata(
48
+ propertyKey,
49
+ handlers,
50
+ target,
51
+ CONTROLLER_MIDDLEWARE,
52
+ );
53
+ };
54
+ }
55
+
56
+ export function ClassMiddleware(handlers: RequestHandler[]) {
57
+ return function (target: any): void {
58
+ Reflect.defineMetadata(CONTROLLER_CLASS_MIDDLEWARE, handlers, target);
59
+ };
60
+ }
61
+
62
+ function createHttpMethod(method: "get" | "post" | "put" | "delete" | "patch") {
63
+ return function (path?: string) {
64
+ return function (target: any, propertyKey: any): any {
65
+ Reflect.defineMetadata(propertyKey, method, target, CONTROLLER_METHOD);
66
+ Reflect.defineMetadata(propertyKey, path, target, CONTROLLER_PATH);
67
+ };
68
+ };
69
+ }
70
+
71
+ export const Get = createHttpMethod("get");
72
+ export const Post = createHttpMethod("post");
73
+ export const Put = createHttpMethod("put");
74
+ export const Patch = createHttpMethod("patch");
75
+ export const Delete = createHttpMethod("delete");
package/src/di.ts ADDED
@@ -0,0 +1,29 @@
1
+ export class DI {
2
+ static new(target: any): any {
3
+ const params = DI.getParams(target);
4
+
5
+ if (!params) {
6
+ return Reflect.construct(target, []);
7
+ }
8
+
9
+ const instantiatedParams = params.map(DI.instantiateAndDIParam);
10
+
11
+ return Reflect.construct(target, instantiatedParams);
12
+ }
13
+
14
+ private static instantiateAndDIParam(param: any) {
15
+ if (!param) return;
16
+
17
+ const hasParams = DI.getParams(param);
18
+
19
+ if (hasParams) {
20
+ return DI.new(param);
21
+ }
22
+
23
+ return Reflect.construct(param, []);
24
+ }
25
+
26
+ private static getParams(target: any): Array<any> {
27
+ return Reflect.getMetadata("design:paramtypes", target);
28
+ }
29
+ }
@@ -0,0 +1,127 @@
1
+ import express, { Router, type RequestHandler } from "express";
2
+ import {
3
+ CONTROLLER_CLASS_MIDDLEWARE,
4
+ CONTROLLER_METHOD,
5
+ CONTROLLER_MIDDLEWARE,
6
+ CONTROLLER_PATH,
7
+ SERVER_CONTROLLERS,
8
+ SERVER_ROUTER,
9
+ } from "./consts";
10
+
11
+ type HttpClient = express.Application;
12
+
13
+ export class AppRouter {
14
+ private static instance = Router();
15
+
16
+ static get() {
17
+ return AppRouter.instance;
18
+ }
19
+ }
20
+
21
+ export class Server {
22
+ private readonly app: HttpClient;
23
+
24
+ constructor() {
25
+ this.app = express();
26
+ this.app.use(express.json());
27
+ this.setupControllers(this.app);
28
+ }
29
+
30
+ start(port: number = 3000) {
31
+ this.app.listen(port, () => {
32
+ console.log(`Application running on port ${port} 🟢`);
33
+ });
34
+ }
35
+
36
+ use(...handlers: RequestHandler[]) {
37
+ this.app.use(handlers);
38
+ }
39
+
40
+ private setupControllers(app: HttpClient) {
41
+ const controllers = this.getControllers();
42
+
43
+ controllers.forEach((controller: any) =>
44
+ this.appendControllerRouterToApp(controller, app),
45
+ );
46
+ }
47
+
48
+ private appendControllerRouterToApp(controller: any, app: any) {
49
+ const router = this.getControllerRouter(controller);
50
+ app.use(router);
51
+ }
52
+
53
+ private getControllers(): Array<any> {
54
+ return Reflect.getMetadata(SERVER_CONTROLLERS, Server);
55
+ }
56
+
57
+ private getControllerRouter(controller: any) {
58
+ return Reflect.getMetadata(SERVER_ROUTER, controller);
59
+ }
60
+
61
+ static appendControllerMetadata(newController: any, controllerRouter: any) {
62
+ const prevControllers = this.getPrevControllers();
63
+
64
+ Reflect.defineMetadata(
65
+ SERVER_CONTROLLERS,
66
+ [...prevControllers, newController],
67
+ Server,
68
+ );
69
+
70
+ Reflect.defineMetadata(SERVER_ROUTER, controllerRouter, newController);
71
+ }
72
+
73
+ private static getPrevControllers() {
74
+ return Reflect.getMetadata(SERVER_CONTROLLERS, Server) || [];
75
+ }
76
+ }
77
+
78
+ export class ControllerActionReader {
79
+ constructor(
80
+ private actionName: string,
81
+ private targetPrototype: any,
82
+ private controllerTarget: any,
83
+ ) {}
84
+
85
+ getMethod() {
86
+ return (
87
+ (Reflect.getMetadata(
88
+ this.actionName,
89
+ this.targetPrototype,
90
+ CONTROLLER_METHOD,
91
+ ) as string) ?? ""
92
+ );
93
+ }
94
+
95
+ getMiddlewares() {
96
+ return (
97
+ (Reflect.getMetadata(
98
+ this.actionName,
99
+ this.targetPrototype,
100
+ CONTROLLER_MIDDLEWARE,
101
+ ) as Array<any>) ?? []
102
+ );
103
+ }
104
+
105
+ getPath() {
106
+ const path =
107
+ Reflect.getOwnMetadata(
108
+ this.actionName,
109
+ this.targetPrototype,
110
+ CONTROLLER_PATH,
111
+ ) ?? "";
112
+
113
+ return this.normalizePath(path);
114
+ }
115
+
116
+ private normalizePath(path: string) {
117
+ if (!path.startsWith("/")) return `/${path}`;
118
+ return path;
119
+ }
120
+
121
+ getControllerClassMiddleware() {
122
+ return Reflect.getMetadata(
123
+ CONTROLLER_CLASS_MIDDLEWARE,
124
+ this.controllerTarget,
125
+ );
126
+ }
127
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import "reflect-metadata";
2
+ import "./di.ts";
3
+
4
+ export * from "./decorators.ts";
5
+ export { Server } from "./http-core.ts";
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "ESNext",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+
23
+ // Some stricter flags (disabled by default)
24
+ "noUnusedLocals": false,
25
+ "noUnusedParameters": false,
26
+ "noPropertyAccessFromIndexSignature": false
27
+ }
28
+ }
@@ -1,4 +0,0 @@
1
- export declare class AppRouter {
2
- private static instance;
3
- static get router(): import("express-serve-static-core").Router;
4
- }
@@ -1,12 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- export declare class Injector {
2
- static inject(target: any): any;
3
- }
@@ -1,24 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,10 +0,0 @@
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 {};
package/classes/Server.js DELETED
@@ -1,32 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- export * from './AppRouter';
2
- export * from './Server';
3
- export * from './Injector';
package/classes/index.js DELETED
@@ -1,20 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB;AACzB,6CAA2B"}
@@ -1 +0,0 @@
1
- export declare function Controller(path: string): (target: any) => any;
@@ -1,34 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,2 +0,0 @@
1
- import type { RequestHandler } from 'express';
2
- export declare function GlobalMiddleware(handlers: RequestHandler[]): (target: any) => void;
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
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;
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
1
- export * from './http-methods.decorator';
2
- export * from './controller.decorator';
3
- export * from './middleware.decorator';
4
- export * from './global-middleware.decorator';
5
- export * from './inject.decorator';
@@ -1,22 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,yDAAuC;AACvC,yDAAuC;AACvC,gEAA8C;AAC9C,qDAAmC"}
@@ -1 +0,0 @@
1
- export declare function Inject(): (_target: any) => void;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Inject = Inject;
4
- function Inject() {
5
- return function (_target) { };
6
- }
7
- //# sourceMappingURL=inject.decorator.js.map
@@ -1 +0,0 @@
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"}
@@ -1,2 +0,0 @@
1
- import type { RequestHandler } from 'express';
2
- export declare function Middleware(handlers: RequestHandler[]): (target: any, propertyKey: any) => any;
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import 'reflect-metadata';
2
- export * from './classes';
3
- export * from './decorators';
4
- export * from './types';
package/index.js DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAA0B;AAE1B,4CAA0B;AAC1B,+CAA6B;AAC7B,0CAAwB"}
@@ -1,6 +0,0 @@
1
- export declare enum ControllerMethodsParams {
2
- Path = "path",
3
- Method = "method",
4
- Middleware = "middleware",
5
- Router = "router"
6
- }
@@ -1,11 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- export declare enum Design {
2
- ParamTypes = "design:paramtypes"
3
- }
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,7 +0,0 @@
1
- export declare enum HttpMethods {
2
- Get = "get",
3
- Post = "post",
4
- Put = "put",
5
- Patch = "patch",
6
- Delete = "delete"
7
- }
@@ -1,12 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
1
- export declare enum ServerConfigsParams {
2
- Router = "router",
3
- GlobalMiddleware = "globalMiddleware",
4
- Controllers = "controllers"
5
- }
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- export * from './ControllerMethodsParams';
2
- export * from './HttpMethods';
3
- export * from './ServerConfigsParams';
@@ -1,20 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/enums/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,gDAA8B;AAC9B,wDAAsC"}
package/types/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './enums';
package/types/index.js DELETED
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}