c2-http 1.0.5 → 1.0.7
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 +4 -4
- package/dist/index.js +8 -42
- package/dist/model/Controller.d.ts +2 -0
- package/dist/model/Controller.js +42 -1
- package/dist/model/CrudController.d.ts +16 -0
- package/dist/model/CrudController.js +65 -0
- package/dist/model/ICrudControllerOptions.d.ts +5 -0
- package/dist/model/ICrudControllerOptions.js +2 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Controller } from "./model/Controller";
|
|
1
|
+
import { Controller, HttpDispatchDownload, HttpDispatchHandling } from "./model/Controller";
|
|
2
|
+
import { CrudController } from "./model/CrudController";
|
|
2
3
|
import { IControllerOptions } from "./model/IControllerOptions";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { Controller, IControllerOptions, HttpDispatchHandling, HttpDispatchDownload };
|
|
4
|
+
import { ICrudControllerOptions } from "./model/ICrudControllerOptions";
|
|
5
|
+
export { Controller, IControllerOptions, CrudController, ICrudControllerOptions, HttpDispatchHandling, HttpDispatchDownload };
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import { INTERNAL_SERVER_ERROR } from "http-status";
|
|
3
|
+
// import { Controller } from "./model/Controller";
|
|
4
|
+
// import { IControllerOptions } from "./model/IControllerOptions";
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0;
|
|
4
|
-
const http_status_1 = require("http-status");
|
|
6
|
+
exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.CrudController = exports.Controller = void 0;
|
|
5
7
|
const Controller_1 = require("./model/Controller");
|
|
6
8
|
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return Controller_1.Controller; } });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const returnHttp = await originalMethod.apply(this, args);
|
|
13
|
-
// const signatureValidation = await ValidateSignatureFlow.validate();
|
|
14
|
-
// if (signatureValidation.expired) {
|
|
15
|
-
// returnHttp[0] = PAYMENT_REQUIRED;
|
|
16
|
-
// }
|
|
17
|
-
return response.status(returnHttp[0]).json(returnHttp[1]);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error(error);
|
|
21
|
-
response
|
|
22
|
-
.status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
|
|
23
|
-
.json({ message: error.message, detail: error.detail?.data });
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
return descriptor;
|
|
27
|
-
}
|
|
28
|
-
exports.HttpDispatchHandling = HttpDispatchHandling;
|
|
29
|
-
function HttpDispatchDownload(target, methodName, descriptor) {
|
|
30
|
-
const originalMethod = descriptor.value;
|
|
31
|
-
descriptor.value = async function (...args) {
|
|
32
|
-
const [response] = args;
|
|
33
|
-
try {
|
|
34
|
-
const [status, data] = await originalMethod.apply(this, args);
|
|
35
|
-
return response.status(status).send(data);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error(error);
|
|
39
|
-
response
|
|
40
|
-
.status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
|
|
41
|
-
.json({ message: error.message, detail: error.detail?.data });
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return descriptor;
|
|
45
|
-
}
|
|
46
|
-
exports.HttpDispatchDownload = HttpDispatchDownload;
|
|
9
|
+
Object.defineProperty(exports, "HttpDispatchDownload", { enumerable: true, get: function () { return Controller_1.HttpDispatchDownload; } });
|
|
10
|
+
Object.defineProperty(exports, "HttpDispatchHandling", { enumerable: true, get: function () { return Controller_1.HttpDispatchHandling; } });
|
|
11
|
+
const CrudController_1 = require("./model/CrudController");
|
|
12
|
+
Object.defineProperty(exports, "CrudController", { enumerable: true, get: function () { return CrudController_1.CrudController; } });
|
|
@@ -5,3 +5,5 @@ export declare abstract class Controller {
|
|
|
5
5
|
protected options: IControllerOptions;
|
|
6
6
|
constructor(_options: Partial<IControllerOptions>);
|
|
7
7
|
}
|
|
8
|
+
export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
9
|
+
export declare function HttpDispatchDownload(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
package/dist/model/Controller.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Controller = void 0;
|
|
3
|
+
exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0;
|
|
4
4
|
const c2_util_1 = require("c2-util");
|
|
5
5
|
const express_1 = require("express");
|
|
6
|
+
const http_status_1 = require("http-status");
|
|
6
7
|
class Controller {
|
|
7
8
|
routers = (0, express_1.Router)();
|
|
8
9
|
options;
|
|
@@ -28,3 +29,43 @@ class Controller {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
exports.Controller = Controller;
|
|
32
|
+
function HttpDispatchHandling(target, methodName, descriptor) {
|
|
33
|
+
const originalMethod = descriptor.value;
|
|
34
|
+
descriptor.value = async function (...args) {
|
|
35
|
+
const response = args[1];
|
|
36
|
+
try {
|
|
37
|
+
const returnHttp = await originalMethod.apply(this, args);
|
|
38
|
+
// const signatureValidation = await ValidateSignatureFlow.validate();
|
|
39
|
+
// if (signatureValidation.expired) {
|
|
40
|
+
// returnHttp[0] = PAYMENT_REQUIRED;
|
|
41
|
+
// }
|
|
42
|
+
return response.status(returnHttp[0]).json(returnHttp[1]);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(error);
|
|
46
|
+
response
|
|
47
|
+
.status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
|
|
48
|
+
.json({ message: error.message, detail: error.detail?.data });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return descriptor;
|
|
52
|
+
}
|
|
53
|
+
exports.HttpDispatchHandling = HttpDispatchHandling;
|
|
54
|
+
function HttpDispatchDownload(target, methodName, descriptor) {
|
|
55
|
+
const originalMethod = descriptor.value;
|
|
56
|
+
descriptor.value = async function (...args) {
|
|
57
|
+
const [response] = args;
|
|
58
|
+
try {
|
|
59
|
+
const [status, data] = await originalMethod.apply(this, args);
|
|
60
|
+
return response.status(status).send(data);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
response
|
|
65
|
+
.status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
|
|
66
|
+
.json({ message: error.message, detail: error.detail?.data });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return descriptor;
|
|
70
|
+
}
|
|
71
|
+
exports.HttpDispatchDownload = HttpDispatchDownload;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { Controller } from "./Controller";
|
|
3
|
+
import { ICrudControllerOptions } from "./ICrudControllerOptions";
|
|
4
|
+
export declare abstract class CrudController extends Controller {
|
|
5
|
+
constructor(options: ICrudControllerOptions);
|
|
6
|
+
abstract search(request: Request, response: Response): Promise<[number, any]>;
|
|
7
|
+
abstract getById(request: Request, response: Response): Promise<[number, any]>;
|
|
8
|
+
abstract create(request: Request, response: Response): Promise<[number, any]>;
|
|
9
|
+
abstract update(request: Request, response: Response): Promise<[number, any]>;
|
|
10
|
+
abstract delete(request: Request, response: Response): Promise<[number, any]>;
|
|
11
|
+
searchRunner(request: Request, response: Response): Promise<[number, any]>;
|
|
12
|
+
getByIdRunner(request: Request, response: Response): Promise<[number, any]>;
|
|
13
|
+
createRunner(request: Request, response: Response): Promise<[number, any]>;
|
|
14
|
+
updateRunner(request: Request, response: Response): Promise<[number, any]>;
|
|
15
|
+
deleteRunner(request: Request, response: Response): Promise<[number, any]>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CrudController = void 0;
|
|
10
|
+
const Controller_1 = require("./Controller");
|
|
11
|
+
class CrudController extends Controller_1.Controller {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
this.searchRunner = this.searchRunner.bind(this);
|
|
15
|
+
this.getByIdRunner = this.getByIdRunner.bind(this);
|
|
16
|
+
this.createRunner = this.createRunner.bind(this);
|
|
17
|
+
this.updateRunner = this.updateRunner.bind(this);
|
|
18
|
+
this.deleteRunner = this.deleteRunner.bind(this);
|
|
19
|
+
if (options.byPass === true || options.middlewareRoles === undefined) {
|
|
20
|
+
this.routers.get(`${this.options.uri}/:id`, this.getByIdRunner);
|
|
21
|
+
this.routers.get(`${this.options.uri}`, this.searchRunner);
|
|
22
|
+
this.routers.post(`${this.options.uri}`, this.createRunner);
|
|
23
|
+
this.routers.patch(`${this.options.uri}/:id`, this.updateRunner);
|
|
24
|
+
this.routers.delete(`${this.options.uri}/:id`, this.deleteRunner);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.routers.get(`${this.options.uri}/:id`, options.middlewareRoles([`${this.options.prefixRole}:read`]), this.getByIdRunner);
|
|
28
|
+
this.routers.get(`${this.options.uri}`, options.middlewareRoles([`${this.options.prefixRole}:read`]), this.searchRunner);
|
|
29
|
+
this.routers.post(`${this.options.uri}`, options.middlewareRoles([`${this.options.prefixRole}:create`]), this.createRunner);
|
|
30
|
+
this.routers.patch(`${this.options.uri}/:id`, options.middlewareRoles([`${this.options.prefixRole}:edit`]), this.updateRunner);
|
|
31
|
+
this.routers.delete(`${this.options.uri}/:id`, options.middlewareRoles([`${this.options.prefixRole}:delete`]), this.deleteRunner);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async searchRunner(request, response) {
|
|
35
|
+
return await this.search(request, response);
|
|
36
|
+
}
|
|
37
|
+
async getByIdRunner(request, response) {
|
|
38
|
+
return await this.getById(request, response);
|
|
39
|
+
}
|
|
40
|
+
async createRunner(request, response) {
|
|
41
|
+
return await this.create(request, response);
|
|
42
|
+
}
|
|
43
|
+
async updateRunner(request, response) {
|
|
44
|
+
return await this.update(request, response);
|
|
45
|
+
}
|
|
46
|
+
async deleteRunner(request, response) {
|
|
47
|
+
return await this.delete(request, response);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
__decorate([
|
|
51
|
+
Controller_1.HttpDispatchHandling
|
|
52
|
+
], CrudController.prototype, "searchRunner", null);
|
|
53
|
+
__decorate([
|
|
54
|
+
Controller_1.HttpDispatchHandling
|
|
55
|
+
], CrudController.prototype, "getByIdRunner", null);
|
|
56
|
+
__decorate([
|
|
57
|
+
Controller_1.HttpDispatchHandling
|
|
58
|
+
], CrudController.prototype, "createRunner", null);
|
|
59
|
+
__decorate([
|
|
60
|
+
Controller_1.HttpDispatchHandling
|
|
61
|
+
], CrudController.prototype, "updateRunner", null);
|
|
62
|
+
__decorate([
|
|
63
|
+
Controller_1.HttpDispatchHandling
|
|
64
|
+
], CrudController.prototype, "deleteRunner", null);
|
|
65
|
+
exports.CrudController = CrudController;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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>",
|