c2-http 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@ import { CrudController } from "./model/CrudController";
4
4
  import { HttpError } from "./model/HttpError";
5
5
  import { IControllerOptions } from "./model/IControllerOptions";
6
6
  import { ICrudControllerOptions } from "./model/ICrudControllerOptions";
7
- import { Server, IServerConfig } from "./model/Server";
7
+ import { IServerConfig, Server } from "./model/Server";
8
8
  export declare const convertErrorToHttpError: (error: any) => HttpError;
9
- export { Controller, CrudController, IControllerOptions, ICrudControllerOptions, Server, IServerConfig, HttpDispatchDownload, HttpDispatchHandling, getMessage, initializei18n };
9
+ export { Controller, CrudController, HttpDispatchDownload, HttpDispatchHandling, IControllerOptions, ICrudControllerOptions, IServerConfig, Server, getMessage, initializei18n };
package/dist/index.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initializei18n = exports.getMessage = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.Server = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
6
+ exports.initializei18n = exports.getMessage = exports.Server = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
7
8
  const express_http_context_1 = __importDefault(require("express-http-context"));
8
9
  const http_status_1 = require("http-status");
9
10
  const mongodb_1 = require("mongodb");
@@ -20,7 +21,6 @@ Object.defineProperty(exports, "CrudController", { enumerable: true, get: functi
20
21
  const HttpError_1 = require("./model/HttpError");
21
22
  const Server_1 = require("./model/Server");
22
23
  Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } });
23
- const axios_1 = __importDefault(require("axios"));
24
24
  const convertErrorToHttpError = (error) => {
25
25
  if (error instanceof mongodb_1.MongoServerError) {
26
26
  if (error.code === 11000) {
@@ -2,8 +2,11 @@ import { Router } from "express";
2
2
  import { IControllerOptions } from "./IControllerOptions";
3
3
  export declare abstract class Controller {
4
4
  routers: Router;
5
+ documentation: any;
5
6
  protected options: IControllerOptions;
6
7
  constructor(_options: Partial<IControllerOptions>);
8
+ BuildDocumentation(): any;
9
+ private getMethodsUsed;
7
10
  }
8
11
  export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
9
12
  export declare function HttpDispatchDownload(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0;
4
+ /* eslint-disable @typescript-eslint/ban-types */
4
5
  const c2_util_1 = require("c2-util");
5
6
  const express_1 = require("express");
6
7
  const http_status_1 = require("http-status");
7
8
  class Controller {
8
9
  routers = (0, express_1.Router)();
10
+ documentation;
9
11
  options;
10
12
  constructor(_options) {
11
13
  this.options = _options;
@@ -27,6 +29,34 @@ class Controller {
27
29
  }
28
30
  this.options.uri = `${this.options.basePath}${this.options.relativePath}`;
29
31
  }
32
+ // Método para extrair as definições de rota para o OpenApi
33
+ BuildDocumentation() {
34
+ const paths = {};
35
+ this.routers.stack.forEach((route) => {
36
+ if (route.route && route.route.path) {
37
+ const methodsUsed = this.getMethodsUsed(route.route.methods);
38
+ const methods = {};
39
+ methodsUsed.forEach((method) => {
40
+ methods[method] = {};
41
+ });
42
+ paths[route.route.path] = {
43
+ ...paths[route.route.path],
44
+ ...methods
45
+ };
46
+ }
47
+ });
48
+ return paths;
49
+ }
50
+ ;
51
+ getMethodsUsed(obj) {
52
+ const trueProperties = [];
53
+ for (const key in obj) {
54
+ if (obj[key] === true) {
55
+ trueProperties.push(key);
56
+ }
57
+ }
58
+ return trueProperties;
59
+ }
30
60
  }
31
61
  exports.Controller = Controller;
32
62
  function HttpDispatchHandling(target, methodName, descriptor) {
@@ -69,3 +99,52 @@ function HttpDispatchDownload(target, methodName, descriptor) {
69
99
  return descriptor;
70
100
  }
71
101
  exports.HttpDispatchDownload = HttpDispatchDownload;
102
+ // export function CustomDecorator<Controller extends { new (...args: any[]): {} }>(target: Controller) {
103
+ // return class extends target {
104
+ // constructor(...args: any[]) {
105
+ // super(...args); // Chama o construtor da classe original
106
+ // // this.initProperty(); // Executa o método que inicializa a propriedade
107
+ // this.anotherProperty = "valor da outra propriedade"; // Define outra propriedade
108
+ // }
109
+ // // initProperty() {
110
+ // // if (typeof this.exampleProperty === 'undefined') {
111
+ // // this.exampleProperty = "valor inicial da propriedade"; // Inicializa a propriedade
112
+ // // }
113
+ // // }
114
+ // };
115
+ // }
116
+ // // Método para extrair as definições de rota para o OpenApi
117
+ // export function OpenApi(
118
+ // target: any,
119
+ // methodName: string,
120
+ // descriptor: PropertyDescriptor): any {
121
+ // const originalMethod = descriptor.value;
122
+ // const getMethodsUsed = (obj: { [key: string]: boolean }): string[] => {
123
+ // const trueProperties: string[] = [];
124
+ // for (const key in obj) {
125
+ // if (obj[key] === true) {
126
+ // trueProperties.push(key);
127
+ // }
128
+ // }
129
+ // return trueProperties;
130
+ // }
131
+ // descriptor.value = async function (...args: any) {
132
+ // const controller = args as Controller;
133
+ // const paths: { [key: string]: any } = {}
134
+ // controller.routers.stack.forEach((route: any) => {
135
+ // if (route.route && route.route.path) {
136
+ // const methodsUsed = getMethodsUsed(route.route.methods)
137
+ // const methods: { [key: string]: any } = {}
138
+ // methodsUsed.forEach((method: string) => {
139
+ // methods[method] = {}
140
+ // });
141
+ // paths[route.route.path] = {
142
+ // ...paths[route.route.path],
143
+ // ...methods
144
+ // }
145
+ // }
146
+ // });
147
+ // return paths;
148
+ // };
149
+ // return descriptor;
150
+ // };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Biblioteca Typescript para API NodeJS",
5
5
  "repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git",
6
6
  "author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",