@cleivermejia/backend 1.0.0 → 1.0.2

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 (55) hide show
  1. package/dist/core/app.d.ts +9 -0
  2. package/dist/core/app.d.ts.map +1 -0
  3. package/dist/core/app.js +39 -0
  4. package/dist/core/app.js.map +1 -0
  5. package/dist/core/decorators.d.ts +4 -0
  6. package/dist/core/decorators.d.ts.map +1 -0
  7. package/dist/core/decorators.js +18 -0
  8. package/dist/core/decorators.js.map +1 -0
  9. package/dist/core/index.d.ts +2 -0
  10. package/dist/core/index.d.ts.map +1 -0
  11. package/dist/core/index.js +2 -0
  12. package/dist/core/index.js.map +1 -0
  13. package/dist/core/metadata.d.ts +7 -0
  14. package/dist/core/metadata.d.ts.map +1 -0
  15. package/dist/core/metadata.js +10 -0
  16. package/dist/core/metadata.js.map +1 -0
  17. package/dist/core/request.d.ts +5 -0
  18. package/dist/core/request.d.ts.map +1 -0
  19. package/dist/core/request.js +4 -0
  20. package/dist/core/request.js.map +1 -0
  21. package/dist/core/response.d.ts +9 -0
  22. package/dist/core/response.d.ts.map +1 -0
  23. package/dist/core/response.js +18 -0
  24. package/dist/core/response.js.map +1 -0
  25. package/dist/core/router.d.ts +9 -0
  26. package/dist/core/router.d.ts.map +1 -0
  27. package/dist/core/router.js +33 -0
  28. package/dist/core/router.js.map +1 -0
  29. package/{src/enum/method.ts → dist/enum/method.d.ts} +7 -6
  30. package/dist/enum/method.d.ts.map +1 -0
  31. package/dist/enum/method.js +8 -0
  32. package/dist/enum/method.js.map +1 -0
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +2 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/interface/route.d.ts +7 -0
  38. package/dist/interface/route.d.ts.map +1 -0
  39. package/dist/interface/route.js +2 -0
  40. package/dist/interface/route.js.map +1 -0
  41. package/dist/test.d.ts +2 -0
  42. package/dist/test.d.ts.map +1 -0
  43. package/dist/test.js +21 -0
  44. package/dist/test.js.map +1 -0
  45. package/package.json +11 -4
  46. package/src/core/app.ts +0 -56
  47. package/src/core/decorators.ts +0 -24
  48. package/src/core/metadata.ts +0 -13
  49. package/src/core/request.ts +0 -5
  50. package/src/core/response.ts +0 -19
  51. package/src/core/router.ts +0 -38
  52. package/src/index.ts +0 -14
  53. package/src/interface/route.ts +0 -7
  54. package/src/test.ts +0 -27
  55. package/tsconfig.json +0 -43
@@ -0,0 +1,9 @@
1
+ import { Router } from "./router";
2
+ export declare class App {
3
+ router: Router;
4
+ get(path: string, handler: Function): void;
5
+ put(path: string, handler: Function): void;
6
+ use(controller: Function): void;
7
+ listen(port: number, hostname?: string, handler?: (() => void) | undefined): void;
8
+ }
9
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/core/app.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,qBAAa,GAAG;IACP,MAAM,EAAE,MAAM,CAAgB;IAE9B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAInC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAInC,GAAG,CAAC,UAAU,EAAE,QAAQ;IAiBxB,MAAM,CACX,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS;CAgBrC"}
@@ -0,0 +1,39 @@
1
+ import { createServer, IncomingMessage, ServerResponse } from "http";
2
+ import { Response } from "./response";
3
+ import { Router } from "./router";
4
+ import { Request } from "./request";
5
+ import { Metadata } from "./metadata";
6
+ import { Method } from "../enum/method";
7
+ export class App {
8
+ router = new Router();
9
+ get(path, handler) {
10
+ this.router.get(path, handler);
11
+ }
12
+ put(path, handler) {
13
+ this.router.put(path, handler);
14
+ }
15
+ use(controller) {
16
+ const urlBase = Metadata.get(controller.prototype["constructor"])?.path ?? "";
17
+ Object.getOwnPropertyNames(controller.prototype)
18
+ .filter(m => m !== "constructor")
19
+ .forEach((f) => {
20
+ const functionController = controller.prototype[f];
21
+ const route = Metadata.get(functionController);
22
+ if (route && route.method === Method.GET) {
23
+ this.get(urlBase + route.path, (req, res) => {
24
+ res.send(functionController());
25
+ });
26
+ }
27
+ });
28
+ }
29
+ listen(port, hostname, handler) {
30
+ const server = createServer((req, res) => {
31
+ const route = this.router.routes.find((r) => req.method === r.method && req.url === r.path);
32
+ if (route?.handler) {
33
+ route.handler(new Request(req), new Response(res));
34
+ }
35
+ });
36
+ server.listen(port, hostname, handler);
37
+ }
38
+ }
39
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/core/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,MAAM,OAAO,GAAG;IACP,MAAM,GAAW,IAAI,MAAM,EAAE,CAAC;IAE9B,GAAG,CAAC,IAAY,EAAE,OAAiB;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IAEM,GAAG,CAAC,IAAY,EAAE,OAAiB;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IAEM,GAAG,CAAC,UAAoB;QAC7B,MAAM,OAAO,GAAW,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;QAEtF,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC;aAC/C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC;aAChC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE;YACrB,MAAM,kBAAkB,GAAa,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC7D,MAAM,KAAK,GAAsB,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAElE,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;gBACzC,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;oBAC7D,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;gBACjC,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CACX,IAAY,EACZ,QAAiB,EACjB,OAAkC;QAElC,MAAM,MAAM,GAAG,YAAY,CACzB,CAAC,GAAoB,EAAE,GAAoC,EAAE,EAAE;YAC7D,MAAM,KAAK,GAAsB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACtD,CAAC,CAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAC5D,CAAC;YAEF,IAAI,KAAK,EAAE,OAAO,EAAE,CAAC;gBACnB,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CACF,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ declare function Controller(path: string): (constructor: Function) => void;
2
+ declare function Get(path?: string): <This, Args extends any[], Return>(value: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext) => (this: This, ...args: Args) => Return;
3
+ export { Controller, Get };
4
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/core/decorators.ts"],"names":[],"mappings":"AAGA,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,IACb,aAAa,QAAQ,UAGvC;AAED,iBAAS,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,IACP,IAAI,EAAE,IAAI,SAAS,GAAG,EAAE,EAAE,MAAM,EAC/C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EAC5C,SAAS,2BAA2B,YADtB,IAAI,WAAW,IAAI,KAAK,MAAM,CAU/C;AAED,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Method } from "../enum/method";
2
+ import { Metadata } from "./metadata";
3
+ function Controller(path) {
4
+ return function (constructor) {
5
+ Metadata.set(constructor, { method: Method.GET, path });
6
+ };
7
+ }
8
+ function Get(path) {
9
+ return function (value, context) {
10
+ Metadata.set(value, {
11
+ method: Method.GET,
12
+ path: path ?? "",
13
+ });
14
+ return value;
15
+ };
16
+ }
17
+ export { Controller, Get };
18
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/core/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,UAAU,WAAqB;QACpC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,GAAG,CAAC,IAAa;IACxB,OAAO,UACL,KAA4C,EAC5C,OAAoC;QAEpC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE;YAClB,MAAM,EAAE,MAAM,CAAC,GAAG;YAClB,IAAI,EAAE,IAAI,IAAI,EAAE;SACjB,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,IAAI,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Route } from "../interface/route";
2
+ export declare class Metadata {
3
+ private static weakMap;
4
+ static set(target: Function, value: Route): void;
5
+ static get(target: Function): Route | undefined;
6
+ }
7
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAC,OAAO,CAA2C;WAEnD,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK;WAIlC,GAAG,CAAC,MAAM,EAAE,QAAQ;CAGrC"}
@@ -0,0 +1,10 @@
1
+ export class Metadata {
2
+ static weakMap = new WeakMap();
3
+ static set(target, value) {
4
+ Metadata.weakMap.set(target, value);
5
+ }
6
+ static get(target) {
7
+ return Metadata.weakMap.get(target);
8
+ }
9
+ }
10
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,QAAQ;IACT,MAAM,CAAC,OAAO,GAA6B,IAAI,OAAO,EAAE,CAAC;IAE1D,MAAM,CAAC,GAAG,CAAC,MAAgB,EAAE,KAAY;QAC5C,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,GAAG,CAAC,MAAgB;QAC9B,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { IncomingMessage } from "http";
2
+ export declare class Request {
3
+ constructor(req: IncomingMessage);
4
+ }
5
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/core/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,qBAAa,OAAO;gBACJ,GAAG,EAAE,eAAe;CACnC"}
@@ -0,0 +1,4 @@
1
+ export class Request {
2
+ constructor(req) { }
3
+ }
4
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/core/request.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,OAAO;IAChB,YAAY,GAAoB,IAAG,CAAC;CACvC"}
@@ -0,0 +1,9 @@
1
+ import type { ServerResponse } from "http";
2
+ export declare class Response {
3
+ private res;
4
+ constructor(res: ServerResponse);
5
+ json(data: unknown): void;
6
+ html(text: string): void;
7
+ send(text: string): void;
8
+ }
9
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/core/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,qBAAa,QAAQ;IACP,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,cAAc;IAEhC,IAAI,CAAC,IAAI,EAAE,OAAO;IAKlB,IAAI,CAAC,IAAI,EAAE,MAAM;IAKjB,IAAI,CAAC,IAAI,EAAE,MAAM;CAGzB"}
@@ -0,0 +1,18 @@
1
+ export class Response {
2
+ res;
3
+ constructor(res) {
4
+ this.res = res;
5
+ }
6
+ json(data) {
7
+ this.res.setHeader("Content-Type", "application/json");
8
+ this.res.end(JSON.stringify(data));
9
+ }
10
+ html(text) {
11
+ this.res.setHeader("Content-Type", "text/html");
12
+ this.res.end(text);
13
+ }
14
+ send(text) {
15
+ this.res.end(text.toString());
16
+ }
17
+ }
18
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/core/response.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,QAAQ;IACC;IAApB,YAAoB,GAAmB;QAAnB,QAAG,GAAH,GAAG,CAAgB;IAAG,CAAC;IAEpC,IAAI,CAAC,IAAa;QACvB,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QACvD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,CAAC;IAEM,IAAI,CAAC,IAAY;QACtB,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QAChD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,IAAI,CAAC,IAAY;QACtB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import type { Route } from "../interface/route";
2
+ export declare class Router {
3
+ routes: Route[];
4
+ get(path: string, handler: Function): void;
5
+ put(path: string, handler: Function): void;
6
+ delete(path: string, handler: Function): void;
7
+ post(path: string, handler: Function): void;
8
+ }
9
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,qBAAa,MAAM;IACV,MAAM,EAAE,KAAK,EAAE,CAAM;IAErB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAQnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAQnC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAQtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;CAO5C"}
@@ -0,0 +1,33 @@
1
+ import { Method } from "../enum/method";
2
+ export class Router {
3
+ routes = [];
4
+ get(path, handler) {
5
+ this.routes.push({
6
+ method: Method.GET,
7
+ path,
8
+ handler,
9
+ });
10
+ }
11
+ put(path, handler) {
12
+ this.routes.push({
13
+ method: Method.PUT,
14
+ path,
15
+ handler,
16
+ });
17
+ }
18
+ delete(path, handler) {
19
+ this.routes.push({
20
+ method: Method.DELETE,
21
+ path,
22
+ handler,
23
+ });
24
+ }
25
+ post(path, handler) {
26
+ this.routes.push({
27
+ method: Method.POST,
28
+ path,
29
+ handler,
30
+ });
31
+ }
32
+ }
33
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,MAAM,OAAO,MAAM;IACV,MAAM,GAAY,EAAE,CAAC;IAErB,GAAG,CAAC,IAAY,EAAE,OAAiB;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,MAAM,CAAC,GAAG;YAClB,IAAI;YACJ,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEM,GAAG,CAAC,IAAY,EAAE,OAAiB;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,MAAM,CAAC,GAAG;YAClB,IAAI;YACJ,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,IAAY,EAAE,OAAiB;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,IAAI;YACJ,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEM,IAAI,CAAC,IAAY,EAAE,OAAiB;QACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,MAAM,CAAC,IAAI;YACnB,IAAI;YACJ,OAAO;SACR,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,6 +1,7 @@
1
- export enum Method {
2
- GET = "GET",
3
- PUT = "PUT",
4
- DELETE = "DELETE",
5
- POST = "POST"
6
- }
1
+ export declare enum Method {
2
+ GET = "GET",
3
+ PUT = "PUT",
4
+ DELETE = "DELETE",
5
+ POST = "POST"
6
+ }
7
+ //# sourceMappingURL=method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../src/enum/method.ts"],"names":[],"mappings":"AAAA,oBAAY,MAAM;IACd,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,IAAI,SAAS;CAChB"}
@@ -0,0 +1,8 @@
1
+ export var Method;
2
+ (function (Method) {
3
+ Method["GET"] = "GET";
4
+ Method["PUT"] = "PUT";
5
+ Method["DELETE"] = "DELETE";
6
+ Method["POST"] = "POST";
7
+ })(Method || (Method = {}));
8
+ //# sourceMappingURL=method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.js","sourceRoot":"","sources":["../../src/enum/method.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,MAKX;AALD,WAAY,MAAM;IACd,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,2BAAiB,CAAA;IACjB,uBAAa,CAAA;AACjB,CAAC,EALW,MAAM,KAAN,MAAM,QAKjB"}
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { Method } from "../enum/method";
2
+ export interface Route {
3
+ method: Method;
4
+ path: string;
5
+ handler?: Function;
6
+ }
7
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/interface/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,QAAQ,CAAA;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/interface/route.ts"],"names":[],"mappings":""}
package/dist/test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}
package/dist/test.js ADDED
@@ -0,0 +1,21 @@
1
+ import { App } from "./core/app";
2
+ import { Controller, Get } from "./core/decorators";
3
+ const app = new App();
4
+ @Controller("/user")
5
+ class User {
6
+ @Get()
7
+ getAll() {
8
+ return JSON.stringify({
9
+ "id": 1,
10
+ "name": "jhon"
11
+ });
12
+ }
13
+ }
14
+ app.use(User);
15
+ app.get("/user2", (req, res) => {
16
+ res.send("Asi tambien se puede hacer la api!");
17
+ });
18
+ app.listen(3000, "localhost", () => {
19
+ console.log(":p");
20
+ });
21
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAIpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAEtB,CAAC,UAAU,CAAC,OAAO,CAAC;MACd,IAAI;IACR,CAAC,GAAG,EAAE;IACN,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,IAAI,EAAE,CAAC;YACP,MAAM,EAAE,MAAM;SACf,CAAC,CAAC;IACL,CAAC;CACF;AAED,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAEd,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAChD,GAAG,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;AAChD,CAAC,CAAC,CAAA;AAEF,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;IACjC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "@cleivermejia/backend",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
6
10
  "scripts": {
7
11
  "test": "tsx watch src/test.ts",
8
- "dev": "tsx watch src/index.ts"
12
+ "dev": "tsx watch src/index.ts",
13
+ "clean": "npx rimraf dist",
14
+ "build": "npm run clean && tsc && tsc-alias"
9
15
  },
10
16
  "keywords": [],
11
17
  "author": "",
12
18
  "license": "ISC",
13
- "type": "commonjs",
19
+ "type": "module",
14
20
  "devDependencies": {
15
21
  "@types/node": "^25.9.2",
22
+ "tsc-alias": "^1.8.17",
16
23
  "typescript": "^6.0.3"
17
24
  }
18
25
  }
package/src/core/app.ts DELETED
@@ -1,56 +0,0 @@
1
- import { createServer, IncomingMessage, ServerResponse } from "http";
2
- import type { Route } from "../interface/route";
3
- import { Response } from "./response";
4
- import { Router } from "./router";
5
- import { Request } from "./request";
6
- import { Metadata } from "./metadata";
7
- import { Method } from "../enum/method";
8
-
9
- export class App {
10
- public router: Router = new Router();
11
-
12
- public get(path: string, handler: Function) {
13
- this.router.get(path, handler);
14
- }
15
-
16
- public put(path: string, handler: Function) {
17
- this.router.put(path, handler);
18
- }
19
-
20
- public use(controller: Function) {
21
- const urlBase: string = Metadata.get(controller.prototype["constructor"])?.path ?? "";
22
-
23
- Object.getOwnPropertyNames(controller.prototype)
24
- .filter(m => m !== "constructor")
25
- .forEach((f: string) => {
26
- const functionController: Function = controller.prototype[f];
27
- const route: Route | undefined = Metadata.get(functionController);
28
-
29
- if (route && route.method === Method.GET) {
30
- this.get(urlBase + route.path, (req: Request, res: Response) => {
31
- res.send(functionController());
32
- });
33
- }
34
- });
35
- }
36
-
37
- public listen(
38
- port: number,
39
- hostname?: string,
40
- handler?: (() => void) | undefined,
41
- ) {
42
- const server = createServer(
43
- (req: IncomingMessage, res: ServerResponse<IncomingMessage>) => {
44
- const route: Route | undefined = this.router.routes.find(
45
- (r: Route) => req.method === r.method && req.url === r.path,
46
- );
47
-
48
- if (route?.handler) {
49
- route.handler(new Request(req), new Response(res));
50
- }
51
- },
52
- );
53
-
54
- server.listen(port, hostname, handler);
55
- }
56
- }
@@ -1,24 +0,0 @@
1
- import { Method } from "../enum/method";
2
- import { Metadata } from "./metadata";
3
-
4
- function Controller(path: string) {
5
- return function (constructor: Function) {
6
- Metadata.set(constructor, { method: Method.GET, path });
7
- };
8
- }
9
-
10
- function Get(path?: string) {
11
- return function <This, Args extends any[], Return>(
12
- value: (this: This, ...args: Args) => Return,
13
- context: ClassMethodDecoratorContext,
14
- ) {
15
- Metadata.set(value, {
16
- method: Method.GET,
17
- path: path ?? "",
18
- });
19
-
20
- return value;
21
- };
22
- }
23
-
24
- export { Controller, Get };
@@ -1,13 +0,0 @@
1
- import type { Route } from "../interface/route";
2
-
3
- export class Metadata {
4
- private static weakMap: WeakMap<Function, Route> = new WeakMap();
5
-
6
- public static set(target: Function, value: Route) {
7
- Metadata.weakMap.set(target, value);
8
- }
9
-
10
- public static get(target: Function) {
11
- return Metadata.weakMap.get(target);
12
- }
13
- }
@@ -1,5 +0,0 @@
1
- import type { IncomingMessage } from "http";
2
-
3
- export class Request {
4
- constructor(req: IncomingMessage) {}
5
- }
@@ -1,19 +0,0 @@
1
- import type { ServerResponse } from "http";
2
-
3
- export class Response {
4
- constructor(private res: ServerResponse) {}
5
-
6
- public json(data: unknown) {
7
- this.res.setHeader("Content-Type", "application/json");
8
- this.res.end(JSON.stringify(data));
9
- }
10
-
11
- public html(text: string) {
12
- this.res.setHeader("Content-Type", "text/html");
13
- this.res.end(text);
14
- }
15
-
16
- public send(text: string) {
17
- this.res.end(text.toString());
18
- }
19
- }
@@ -1,38 +0,0 @@
1
- import { Method } from "../enum/method";
2
- import type { Route } from "../interface/route";
3
-
4
- export class Router {
5
- public routes: Route[] = [];
6
-
7
- public get(path: string, handler: Function) {
8
- this.routes.push({
9
- method: Method.GET,
10
- path,
11
- handler,
12
- });
13
- }
14
-
15
- public put(path: string, handler: Function) {
16
- this.routes.push({
17
- method: Method.PUT,
18
- path,
19
- handler,
20
- });
21
- }
22
-
23
- public delete(path: string, handler: Function) {
24
- this.routes.push({
25
- method: Method.DELETE,
26
- path,
27
- handler,
28
- });
29
- }
30
-
31
- public post(path: string, handler: Function) {
32
- this.routes.push({
33
- method: Method.POST,
34
- path,
35
- handler,
36
- });
37
- }
38
- }
package/src/index.ts DELETED
@@ -1,14 +0,0 @@
1
- import { App } from "./core/app";
2
- import type { Request } from "./core/request";
3
- import type { Response } from "./core/response";
4
-
5
- const app = new App();
6
- const PORT = 3000;
7
-
8
- app.get("/", (req: Request, res: Response) => {
9
- res.html('<h1>Hola mundo!</h1>');
10
- });
11
-
12
- app.listen(PORT, "localhost", () =>
13
- console.log(`Servidor encendido http://localhost:${PORT}`),
14
- );
@@ -1,7 +0,0 @@
1
- import type { Method } from "../enum/method"
2
-
3
- export interface Route {
4
- method: Method
5
- path: string,
6
- handler?: Function
7
- }
package/src/test.ts DELETED
@@ -1,27 +0,0 @@
1
- import { App } from "./core/app";
2
- import { Controller, Get } from "./core/decorators";
3
- import type { Request } from "./core/request";
4
- import type { Response } from "./core/response";
5
-
6
- const app = new App();
7
-
8
- @Controller("/user")
9
- class User {
10
- @Get()
11
- getAll() {
12
- return JSON.stringify({
13
- "id": 1,
14
- "name": "jhon"
15
- });
16
- }
17
- }
18
-
19
- app.use(User);
20
-
21
- app.get("/user2", (req: Request, res: Response) => {
22
- res.send("Asi tambien se puede hacer la api!")
23
- })
24
-
25
- app.listen(3000, "localhost", () => {
26
- console.log(":p");
27
- });
package/tsconfig.json DELETED
@@ -1,43 +0,0 @@
1
- {
2
- // Visit https://aka.ms/tsconfig to read more about this file
3
- "compilerOptions": {
4
- // File Layout
5
- // "rootDir": "./src",
6
- // "outDir": "./dist",
7
-
8
- // Environment Settings
9
- // See also https://aka.ms/tsconfig/module
10
- "module": "esnext",
11
- "target": "esnext",
12
- // For nodejs:
13
- // "lib": ["esnext"],
14
- "types": ["node"],
15
- // and npm install -D @types/node
16
-
17
- // Other Outputs
18
- "sourceMap": true,
19
- "declaration": true,
20
- "declarationMap": true,
21
-
22
- // Stricter Typechecking Options
23
- "noUncheckedIndexedAccess": true,
24
- "exactOptionalPropertyTypes": true,
25
-
26
- // Style Options
27
- // "noImplicitReturns": true,
28
- // "noImplicitOverride": true,
29
- // "noUnusedLocals": true,
30
- // "noUnusedParameters": true,
31
- // "noFallthroughCasesInSwitch": true,
32
- // "noPropertyAccessFromIndexSignature": true,
33
-
34
- // Recommended Options
35
- "strict": true,
36
- "jsx": "react-jsx",
37
- "verbatimModuleSyntax": true,
38
- "isolatedModules": true,
39
- "noUncheckedSideEffectImports": true,
40
- "moduleDetection": "force",
41
- "skipLibCheck": true,
42
- }
43
- }