@atlantjs/backend 11.0.5 → 11.0.6

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.
@@ -1,7 +1,12 @@
1
- import { HttpContentTypePoint } from "./http-content-type.point";
2
- import "reflect-metadata";
3
- export declare const Get: (route: string, contentType?: HttpContentTypePoint) => ClassDecorator;
4
- export declare const Post: (route: string, contentType?: HttpContentTypePoint) => ClassDecorator;
5
- export declare const Put: (route: string, contentType?: HttpContentTypePoint) => ClassDecorator;
6
- export declare const Patch: (route: string, contentType?: HttpContentTypePoint) => ClassDecorator;
7
- export declare const Delete: (route: string, contentType?: HttpContentTypePoint) => ClassDecorator;
1
+ import { ControllerOptions } from "routing-controllers/types/decorator-options/ControllerOptions";
2
+ interface UnifiedControllerOptions extends ControllerOptions {
3
+ route: string;
4
+ method: "get" | "post" | "put" | "patch" | "delete";
5
+ }
6
+ export declare function UnifiedController(options: UnifiedControllerOptions): ClassDecorator;
7
+ export declare const Get: (route: string) => ClassDecorator;
8
+ export declare const Post: (route: string) => ClassDecorator;
9
+ export declare const Put: (route: string) => ClassDecorator;
10
+ export declare const Patch: (route: string) => ClassDecorator;
11
+ export declare const Delete: (route: string) => ClassDecorator;
12
+ export {};
@@ -1,33 +1,67 @@
1
1
  "use strict";
2
+ // import { HttpContentTypePoint } from "./http-content-type.point";
3
+ // import { HttpMethodPoint } from "./http-method.point";
4
+ // import "reflect-metadata";
5
+ // import { getMetadataArgsStorage } from "routing-controllers";
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0;
4
- const http_content_type_point_1 = require("./http-content-type.point");
5
- const http_method_point_1 = require("./http-method.point");
6
- require("reflect-metadata");
8
+ exports.UnifiedController = UnifiedController;
9
+ // function HttpMethod(httpMethod: HttpMethodPoint) {
10
+ // return (
11
+ // route: string,
12
+ // contentType = HttpContentTypePoint.JSON,
13
+ // ): ClassDecorator => {
14
+ // return (target) => {
15
+ // getMetadataArgsStorage().actions.push({
16
+ // type: httpMethod,
17
+ // target: target.constructor,
18
+ // method: "apply",
19
+ // route,
20
+ // options: {},
21
+ // });
22
+ // if (contentType === HttpContentTypePoint.JSON) {
23
+ // getMetadataArgsStorage().controllers.push({
24
+ // type: "json",
25
+ // target: target,
26
+ // route,
27
+ // options: {},
28
+ // });
29
+ // }
30
+ // };
31
+ // };
32
+ // }
33
+ // export const Get = HttpMethod(HttpMethodPoint.GET);
34
+ // export const Post = HttpMethod(HttpMethodPoint.POST);
35
+ // export const Put = HttpMethod(HttpMethodPoint.PUT);
36
+ // export const Patch = HttpMethod(HttpMethodPoint.PATCH);
37
+ // export const Delete = HttpMethod(HttpMethodPoint.DELETE);
7
38
  const routing_controllers_1 = require("routing-controllers");
8
- function HttpMethod(httpMethod) {
9
- return (route, contentType = http_content_type_point_1.HttpContentTypePoint.JSON) => {
10
- return (target) => {
11
- (0, routing_controllers_1.getMetadataArgsStorage)().actions.push({
12
- type: httpMethod,
13
- target: target.constructor,
14
- method: "apply",
15
- route,
16
- options: {},
17
- });
18
- if (contentType === http_content_type_point_1.HttpContentTypePoint.JSON) {
19
- (0, routing_controllers_1.getMetadataArgsStorage)().controllers.push({
20
- type: "json",
21
- target: target,
22
- route,
23
- options: {},
24
- });
25
- }
26
- };
39
+ function UnifiedController(options) {
40
+ return (target) => {
41
+ // Registra o controller como JSON
42
+ (0, routing_controllers_1.getMetadataArgsStorage)().controllers.push({
43
+ type: "json", // ou options.type se quiser customizar
44
+ target,
45
+ route: options.route,
46
+ options,
47
+ });
48
+ // Registra a action sempre como método 'apply'
49
+ (0, routing_controllers_1.getMetadataArgsStorage)().actions.push({
50
+ type: options.method,
51
+ target,
52
+ method: "apply",
53
+ route: options.route,
54
+ options: {},
55
+ });
27
56
  };
28
57
  }
29
- exports.Get = HttpMethod(http_method_point_1.HttpMethodPoint.GET);
30
- exports.Post = HttpMethod(http_method_point_1.HttpMethodPoint.POST);
31
- exports.Put = HttpMethod(http_method_point_1.HttpMethodPoint.PUT);
32
- exports.Patch = HttpMethod(http_method_point_1.HttpMethodPoint.PATCH);
33
- exports.Delete = HttpMethod(http_method_point_1.HttpMethodPoint.DELETE);
58
+ const Get = (route) => UnifiedController({ method: "get", route });
59
+ exports.Get = Get;
60
+ const Post = (route) => UnifiedController({ method: "post", route });
61
+ exports.Post = Post;
62
+ const Put = (route) => UnifiedController({ method: "put", route });
63
+ exports.Put = Put;
64
+ const Patch = (route) => UnifiedController({ method: "patch", route });
65
+ exports.Patch = Patch;
66
+ const Delete = (route) => UnifiedController({ method: "delete", route });
67
+ exports.Delete = Delete;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlantjs/backend",
3
- "version": "11.0.5",
3
+ "version": "11.0.6",
4
4
  "main": "index.js",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {