ismx-nexo-node-app 0.4.84 → 0.4.85
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/js/business/FormalLoopbackBusiness.js +92 -0
- package/dist/js/business/FormalProxyBusiness.js +92 -0
- package/dist/js/business/LoopbackBusiness.js +44 -0
- package/dist/js/business/{BusinessProxy.js → ProxyBusiness.js} +5 -3
- package/dist/js/index.js +8 -4
- package/dist/types/business/FormalLoopbackBusiness.d.ts +21 -0
- package/dist/types/business/FormalProxyBusiness.d.ts +21 -0
- package/dist/types/business/LoopbackBusiness.d.ts +11 -0
- package/dist/types/business/{BusinessProxy.d.ts → ProxyBusiness.d.ts} +4 -2
- package/dist/types/index.d.ts +9 -6
- package/package.json +1 -1
- package/src/main/node/business/FormalLoopbackBusiness.ts +68 -0
- package/src/main/node/business/FormalProxyBusiness.ts +67 -0
- package/src/main/node/business/LoopbackBusiness.ts +31 -0
- package/src/main/node/business/{BusinessProxy.ts → ProxyBusiness.ts} +5 -4
- package/src/main/node/index.ts +9 -6
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const LoopbackBusiness_1 = __importDefault(require("./LoopbackBusiness"));
|
|
16
|
+
class FormalLoopbackBusiness extends LoopbackBusiness_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
get(tag_1) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
22
|
+
return this.call(tag, 'GET', '/', request);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
list(tag_1) {
|
|
26
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
27
|
+
return this.call(tag, 'GET', '/list', request);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
select(tag_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
32
|
+
return this.call(tag, 'GET', '/select', request);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
count(tag_1) {
|
|
36
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
37
|
+
return this.call(tag, 'GET', '/count', request);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
keymap(tag_1) {
|
|
41
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
42
|
+
return this.call(tag, 'GET', '/keymap', request);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
map(tag_1) {
|
|
46
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
47
|
+
return this.call(tag, 'GET', '/map', request);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exist(tag_1) {
|
|
51
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
52
|
+
return this.call(tag, 'GET', '/exist', request);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
post(tag_1) {
|
|
56
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
57
|
+
return this.call(tag, 'POST', '/', request);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
put(tag_1) {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
62
|
+
return this.call(tag, 'PUT', '/', request);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
del(tag_1) {
|
|
66
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
67
|
+
return this.call(tag, 'DELETE', '/', request);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
call(tag_1, method_1, endpoint_1) {
|
|
71
|
+
const _super = Object.create(null, {
|
|
72
|
+
loopback: { get: () => super.loopback }
|
|
73
|
+
});
|
|
74
|
+
return __awaiter(this, arguments, void 0, function* (tag, method, endpoint, request = {}) {
|
|
75
|
+
return this.deformalize(() => _super.loopback.call(this, method, `${tag}/${endpoint}`, request));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
deformalize(call) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
let result = yield call();
|
|
81
|
+
if (result.ok) {
|
|
82
|
+
let wrapper = yield result.json();
|
|
83
|
+
return wrapper.data;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const errorBody = yield result.json();
|
|
87
|
+
throw new Error(JSON.stringify(errorBody));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.default = FormalLoopbackBusiness;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ProxyBusiness_1 = __importDefault(require("./ProxyBusiness"));
|
|
16
|
+
class FormalProxyBusiness extends ProxyBusiness_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
get(tag_1) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
22
|
+
return this.call(tag, 'GET', '/', request);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
list(tag_1) {
|
|
26
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
27
|
+
return this.call(tag, 'GET', '/list', request);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
select(tag_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
32
|
+
return this.call(tag, 'GET', '/select', request);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
count(tag_1) {
|
|
36
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
37
|
+
return this.call(tag, 'GET', '/count', request);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
keymap(tag_1) {
|
|
41
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
42
|
+
return this.call(tag, 'GET', '/keymap', request);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
map(tag_1) {
|
|
46
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
47
|
+
return this.call(tag, 'GET', '/map', request);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exist(tag_1) {
|
|
51
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
52
|
+
return this.call(tag, 'GET', '/exist', request);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
post(tag_1) {
|
|
56
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
57
|
+
return this.call(tag, 'POST', '/', request);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
put(tag_1) {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
62
|
+
return this.call(tag, 'PUT', '/', request);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
del(tag_1) {
|
|
66
|
+
return __awaiter(this, arguments, void 0, function* (tag, request = {}) {
|
|
67
|
+
return this.call(tag, 'DELETE', '/', request);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
call(tag_1, method_1, endpoint_1) {
|
|
71
|
+
const _super = Object.create(null, {
|
|
72
|
+
call: { get: () => super.call }
|
|
73
|
+
});
|
|
74
|
+
return __awaiter(this, arguments, void 0, function* (tag, method, endpoint, request = {}) {
|
|
75
|
+
return this.deformalize(() => _super.call.call(this, tag, method, endpoint, request));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
deformalize(call) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
let result = yield call();
|
|
81
|
+
if (result.ok) {
|
|
82
|
+
let wrapper = yield result.json();
|
|
83
|
+
return wrapper.data;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const errorBody = yield result.json();
|
|
87
|
+
throw new Error(JSON.stringify(errorBody));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.default = FormalProxyBusiness;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ProxyBusiness_1 = __importDefault(require("./ProxyBusiness"));
|
|
16
|
+
class LoopbackBusiness extends ProxyBusiness_1.default {
|
|
17
|
+
constructor(loopback = "http://localhost") {
|
|
18
|
+
super();
|
|
19
|
+
this.modules = {
|
|
20
|
+
loopback: {
|
|
21
|
+
id: "loopback",
|
|
22
|
+
tag: "loopback",
|
|
23
|
+
host: loopback,
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
call(tag, method, endpoint, request) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this.loopback(method, endpoint, request);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
loopback(method, endpoint, request) {
|
|
33
|
+
const _super = Object.create(null, {
|
|
34
|
+
call: { get: () => super.call }
|
|
35
|
+
});
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return _super.call.call(this, "loopback", endpoint, method, request);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
setModules(modules) {
|
|
41
|
+
throw new Error("Cannot set modules in loopback proxy");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = LoopbackBusiness;
|
|
@@ -37,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const node_fetch_1 = __importStar(require("node-fetch"));
|
|
39
39
|
const QueryUtils_1 = __importDefault(require("../repository/utils/QueryUtils"));
|
|
40
|
-
class
|
|
40
|
+
class ProxyBusiness {
|
|
41
41
|
constructor() {
|
|
42
42
|
this.modules = {};
|
|
43
43
|
this.onError = (error) => error;
|
|
@@ -67,8 +67,10 @@ class BusinessProxy {
|
|
|
67
67
|
body = JSON.stringify(request.body);
|
|
68
68
|
}
|
|
69
69
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
70
|
-
return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers })).catch((error) => {
|
|
70
|
+
return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers })).catch((error) => {
|
|
71
|
+
throw this.onError(error);
|
|
72
|
+
});
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
exports.default =
|
|
76
|
+
exports.default = ProxyBusiness;
|
package/dist/js/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.
|
|
29
|
+
exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
|
|
30
30
|
const Service_1 = __importStar(require("./api/Service"));
|
|
31
31
|
class Service extends Service_1.default {
|
|
32
32
|
}
|
|
@@ -59,10 +59,14 @@ const BusinessState_1 = __importDefault(require("./business/BusinessState"));
|
|
|
59
59
|
class BusinessState extends BusinessState_1.default {
|
|
60
60
|
}
|
|
61
61
|
exports.BusinessState = BusinessState;
|
|
62
|
-
const
|
|
63
|
-
class
|
|
62
|
+
const ProxyBusiness_1 = __importDefault(require("./business/ProxyBusiness"));
|
|
63
|
+
class ProxyBusiness extends ProxyBusiness_1.default {
|
|
64
64
|
}
|
|
65
|
-
exports.
|
|
65
|
+
exports.ProxyBusiness = ProxyBusiness;
|
|
66
|
+
const FormalProxyBusiness_1 = __importDefault(require("./business/FormalProxyBusiness"));
|
|
67
|
+
class FormalProxyBusiness extends FormalProxyBusiness_1.default {
|
|
68
|
+
}
|
|
69
|
+
exports.FormalProxyBusiness = FormalProxyBusiness;
|
|
66
70
|
const BusinessServer_1 = __importDefault(require("./business/BusinessServer"));
|
|
67
71
|
class BusinessServer extends BusinessServer_1.default {
|
|
68
72
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpRequest } from "../api/Service";
|
|
2
|
+
import LoopbackBusiness from "./LoopbackBusiness";
|
|
3
|
+
export default class FormalLoopbackBusiness extends LoopbackBusiness {
|
|
4
|
+
constructor();
|
|
5
|
+
get<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
6
|
+
list<Res>(tag: string, request?: HttpRequest): Promise<Res[]>;
|
|
7
|
+
select(tag: string, request?: HttpRequest): Promise<string[]>;
|
|
8
|
+
count(tag: string, request?: HttpRequest): Promise<number>;
|
|
9
|
+
keymap(tag: string, request?: HttpRequest): Promise<{
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
}>;
|
|
12
|
+
map<Res>(tag: string, request?: HttpRequest): Promise<{
|
|
13
|
+
[key: string]: Res;
|
|
14
|
+
}>;
|
|
15
|
+
exist(tag: string, request?: HttpRequest): Promise<boolean>;
|
|
16
|
+
post<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
17
|
+
put<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
18
|
+
del<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
19
|
+
call<Res>(tag: string, method: string, endpoint: string, request?: HttpRequest): Promise<Res>;
|
|
20
|
+
private deformalize;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpRequest } from "../api/Service";
|
|
2
|
+
import ProxyBusiness from "./ProxyBusiness";
|
|
3
|
+
export default class FormalProxyBusiness extends ProxyBusiness {
|
|
4
|
+
constructor();
|
|
5
|
+
get<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
6
|
+
list<Res>(tag: string, request?: HttpRequest): Promise<Res[]>;
|
|
7
|
+
select(tag: string, request?: HttpRequest): Promise<string[]>;
|
|
8
|
+
count(tag: string, request?: HttpRequest): Promise<number>;
|
|
9
|
+
keymap(tag: string, request?: HttpRequest): Promise<{
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
}>;
|
|
12
|
+
map<Res>(tag: string, request?: HttpRequest): Promise<{
|
|
13
|
+
[key: string]: Res;
|
|
14
|
+
}>;
|
|
15
|
+
exist(tag: string, request?: HttpRequest): Promise<boolean>;
|
|
16
|
+
post<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
17
|
+
put<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
18
|
+
del<Res>(tag: string, request?: HttpRequest): Promise<Res>;
|
|
19
|
+
call<Res>(tag: string, method: string, endpoint: string, request?: HttpRequest): Promise<Res>;
|
|
20
|
+
private deformalize;
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpRequest } from "../api/Service";
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
import ProxyBusiness, { Module } from "./ProxyBusiness";
|
|
4
|
+
export default class LoopbackBusiness extends ProxyBusiness {
|
|
5
|
+
constructor(loopback?: string);
|
|
6
|
+
call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response>;
|
|
7
|
+
loopback<Req, Res>(method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response>;
|
|
8
|
+
setModules(modules: {
|
|
9
|
+
[p: string]: Module;
|
|
10
|
+
}): void;
|
|
11
|
+
}
|
|
@@ -5,8 +5,10 @@ export interface Module {
|
|
|
5
5
|
tag: string;
|
|
6
6
|
host: string;
|
|
7
7
|
}
|
|
8
|
-
export default class
|
|
9
|
-
|
|
8
|
+
export default class ProxyBusiness {
|
|
9
|
+
protected modules: {
|
|
10
|
+
[key: string]: Module;
|
|
11
|
+
};
|
|
10
12
|
private onError;
|
|
11
13
|
setModules(modules: {
|
|
12
14
|
[key: string]: Module;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,19 +26,22 @@ export declare class Business extends BaseBusiness {
|
|
|
26
26
|
import BaseBusinessState from "./business/BusinessState";
|
|
27
27
|
export declare class BusinessState<M = any> extends BaseBusinessState<M> {
|
|
28
28
|
}
|
|
29
|
-
import
|
|
30
|
-
export declare class
|
|
29
|
+
import BaseProxyBusiness, { Module as BaseModule } from "./business/ProxyBusiness";
|
|
30
|
+
export declare class ProxyBusiness extends BaseProxyBusiness {
|
|
31
31
|
}
|
|
32
32
|
export interface Module extends BaseModule {
|
|
33
33
|
}
|
|
34
|
+
import _FormalProxyBusiness from "./business/FormalProxyBusiness";
|
|
35
|
+
export declare class FormalProxyBusiness extends _FormalProxyBusiness {
|
|
36
|
+
}
|
|
34
37
|
import _BusinessServer from "./business/BusinessServer";
|
|
35
38
|
export declare class BusinessServer extends _BusinessServer {
|
|
36
39
|
}
|
|
37
|
-
import
|
|
38
|
-
export declare abstract class BusinessThread extends
|
|
40
|
+
import _BusinessThread from "./business/BusinessThread";
|
|
41
|
+
export declare abstract class BusinessThread extends _BusinessThread {
|
|
39
42
|
}
|
|
40
|
-
import
|
|
41
|
-
export declare abstract class BusinessThreadState<Model = any> extends
|
|
43
|
+
import _BusinessThreadState from "./business/BusinessThreadState";
|
|
44
|
+
export declare abstract class BusinessThreadState<Model = any> extends _BusinessThreadState<Model> {
|
|
42
45
|
}
|
|
43
46
|
import BaseBusinessErrors, { ErrorType as _ErrorType, FormalError as _FormalError } from "./business/BusinessErrors";
|
|
44
47
|
export declare class BusinessErrors extends BaseBusinessErrors {
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {HttpRequest} from "../api/Service";
|
|
2
|
+
import ProxyBusiness from "./ProxyBusiness";
|
|
3
|
+
import {Wrapper} from "../api/ServiceRestFormal";
|
|
4
|
+
import Business from "./Business";
|
|
5
|
+
import fetch from "node-fetch";
|
|
6
|
+
import LoopbackBusiness from "./LoopbackBusiness";
|
|
7
|
+
|
|
8
|
+
export default class FormalLoopbackBusiness extends LoopbackBusiness {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async get<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
15
|
+
return this.call<Res>(tag, 'GET', '/', request);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async list<Res>(tag: string, request: HttpRequest = {}): Promise<Res[]> {
|
|
19
|
+
return this.call<Res[]>(tag, 'GET', '/list', request);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async select(tag: string, request: HttpRequest = {}): Promise<string[]> {
|
|
23
|
+
return this.call<string[]>(tag, 'GET', '/select', request);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async count(tag: string, request: HttpRequest = {}): Promise<number> {
|
|
27
|
+
return this.call<number>(tag, 'GET', '/count', request);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async keymap(tag: string, request: HttpRequest = {}): Promise<{ [key:string]: string }> {
|
|
31
|
+
return this.call<{ [key:string]: string }>(tag, 'GET', '/keymap', request);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async map<Res>(tag: string, request: HttpRequest = {}): Promise<{ [key:string]: Res }> {
|
|
35
|
+
return this.call<{ [key:string]: Res }>(tag, 'GET', '/map', request);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async exist(tag: string, request: HttpRequest = {}): Promise<boolean> {
|
|
39
|
+
return this.call<boolean>(tag, 'GET', '/exist', request);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async post<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
43
|
+
return this.call<Res>(tag, 'POST', '/', request);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async put<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
47
|
+
return this.call<Res>(tag, 'PUT', '/', request);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async del<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
51
|
+
return this.call<Res>(tag, 'DELETE', '/', request);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async call<Res>(tag: string, method: string, endpoint: string, request: HttpRequest = {}): Promise<Res> {
|
|
55
|
+
return this.deformalize(() => super.loopback<any, Wrapper<Res>>(method, `${tag}/${endpoint}`, request));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async deformalize<Res>(call: () => Promise<fetch.Response>): Promise<Res> {
|
|
59
|
+
let result = await call();
|
|
60
|
+
if (result.ok) {
|
|
61
|
+
let wrapper = await result.json() as Wrapper<Res>;
|
|
62
|
+
return wrapper.data;
|
|
63
|
+
} else {
|
|
64
|
+
const errorBody = await result.json();
|
|
65
|
+
throw new Error(JSON.stringify(errorBody));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {HttpRequest} from "../api/Service";
|
|
2
|
+
import ProxyBusiness from "./ProxyBusiness";
|
|
3
|
+
import {Wrapper} from "../api/ServiceRestFormal";
|
|
4
|
+
import Business from "./Business";
|
|
5
|
+
import fetch from "node-fetch";
|
|
6
|
+
|
|
7
|
+
export default class FormalProxyBusiness extends ProxyBusiness {
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async get<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
14
|
+
return this.call<Res>(tag, 'GET', '/', request);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async list<Res>(tag: string, request: HttpRequest = {}): Promise<Res[]> {
|
|
18
|
+
return this.call<Res[]>(tag, 'GET', '/list', request);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async select(tag: string, request: HttpRequest = {}): Promise<string[]> {
|
|
22
|
+
return this.call<string[]>(tag, 'GET', '/select', request);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async count(tag: string, request: HttpRequest = {}): Promise<number> {
|
|
26
|
+
return this.call<number>(tag, 'GET', '/count', request);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async keymap(tag: string, request: HttpRequest = {}): Promise<{ [key:string]: string }> {
|
|
30
|
+
return this.call<{ [key:string]: string }>(tag, 'GET', '/keymap', request);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async map<Res>(tag: string, request: HttpRequest = {}): Promise<{ [key:string]: Res }> {
|
|
34
|
+
return this.call<{ [key:string]: Res }>(tag, 'GET', '/map', request);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async exist(tag: string, request: HttpRequest = {}): Promise<boolean> {
|
|
38
|
+
return this.call<boolean>(tag, 'GET', '/exist', request);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async post<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
42
|
+
return this.call<Res>(tag, 'POST', '/', request);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async put<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
46
|
+
return this.call<Res>(tag, 'PUT', '/', request);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async del<Res>(tag: string, request: HttpRequest = {}): Promise<Res> {
|
|
50
|
+
return this.call<Res>(tag, 'DELETE', '/', request);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async call<Res>(tag: string, method: string, endpoint: string, request: HttpRequest = {}): Promise<Res> {
|
|
54
|
+
return this.deformalize(() => super.call<any, Wrapper<Res>>(tag, method, endpoint, request));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private async deformalize<Res>(call: () => Promise<fetch.Response>): Promise<Res> {
|
|
58
|
+
let result = await call();
|
|
59
|
+
if (result.ok) {
|
|
60
|
+
let wrapper = await result.json() as Wrapper<Res>;
|
|
61
|
+
return wrapper.data;
|
|
62
|
+
} else {
|
|
63
|
+
const errorBody = await result.json();
|
|
64
|
+
throw new Error(JSON.stringify(errorBody));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HttpResponse, HttpRequest } from "../api/Service"
|
|
2
|
+
import fetch, {Body, Headers} from 'node-fetch';
|
|
3
|
+
import QueryUtils from "../repository/utils/QueryUtils";
|
|
4
|
+
import ProxyBusiness, {Module} from "./ProxyBusiness";
|
|
5
|
+
import FormalProxyBusiness from "./FormalProxyBusiness";
|
|
6
|
+
|
|
7
|
+
export default class LoopbackBusiness extends ProxyBusiness
|
|
8
|
+
{
|
|
9
|
+
constructor(loopback = "http://localhost") {
|
|
10
|
+
super();
|
|
11
|
+
this.modules = {
|
|
12
|
+
loopback: {
|
|
13
|
+
id: "loopback",
|
|
14
|
+
tag: "loopback",
|
|
15
|
+
host: loopback,
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response> {
|
|
21
|
+
return this.loopback(method, endpoint, request);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async loopback<Req, Res>(method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response> {
|
|
25
|
+
return super.call<Req, Res>("loopback", endpoint, method, request);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setModules(modules: { [p: string]: Module }) {
|
|
29
|
+
throw new Error("Cannot set modules in loopback proxy");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { HttpResponse, HttpRequest } from "../api/Service"
|
|
2
2
|
import fetch, {Body, Headers} from 'node-fetch';
|
|
3
3
|
import QueryUtils from "../repository/utils/QueryUtils";
|
|
4
|
-
import {json} from "express";
|
|
5
4
|
|
|
6
5
|
export interface Module {
|
|
7
6
|
id: string;
|
|
@@ -9,9 +8,9 @@ export interface Module {
|
|
|
9
8
|
host: string;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
export default class
|
|
11
|
+
export default class ProxyBusiness
|
|
13
12
|
{
|
|
14
|
-
|
|
13
|
+
protected modules: {[key:string]: Module} = {};
|
|
15
14
|
private onError: (error: Error) => Error = (error) => error;
|
|
16
15
|
|
|
17
16
|
setModules(modules: {[key:string]: Module}) {
|
|
@@ -43,6 +42,8 @@ export default class BusinessProxy
|
|
|
43
42
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
44
43
|
return fetch(module.host + endpoint + QueryUtils.map(request.query), {
|
|
45
44
|
...request, method, body: method !== "GET" ? body : undefined, headers
|
|
46
|
-
}).catch((error) => {
|
|
45
|
+
}).catch((error) => {
|
|
46
|
+
throw this.onError(error)
|
|
47
|
+
});
|
|
47
48
|
}
|
|
48
49
|
}
|
package/src/main/node/index.ts
CHANGED
|
@@ -24,18 +24,21 @@ export class Business extends BaseBusiness {}
|
|
|
24
24
|
import BaseBusinessState from "./business/BusinessState";
|
|
25
25
|
export class BusinessState<M=any> extends BaseBusinessState<M> {}
|
|
26
26
|
|
|
27
|
-
import
|
|
28
|
-
export class
|
|
27
|
+
import BaseProxyBusiness, { Module as BaseModule } from "./business/ProxyBusiness";
|
|
28
|
+
export class ProxyBusiness extends BaseProxyBusiness {}
|
|
29
29
|
export interface Module extends BaseModule {}
|
|
30
30
|
|
|
31
|
+
import _FormalProxyBusiness from "./business/FormalProxyBusiness";
|
|
32
|
+
export class FormalProxyBusiness extends _FormalProxyBusiness {}
|
|
33
|
+
|
|
31
34
|
import _BusinessServer from "./business/BusinessServer";
|
|
32
35
|
export class BusinessServer extends _BusinessServer {}
|
|
33
36
|
|
|
34
|
-
import
|
|
35
|
-
export abstract class BusinessThread extends
|
|
37
|
+
import _BusinessThread from "./business/BusinessThread";
|
|
38
|
+
export abstract class BusinessThread extends _BusinessThread {}
|
|
36
39
|
|
|
37
|
-
import
|
|
38
|
-
export abstract class BusinessThreadState<Model=any> extends
|
|
40
|
+
import _BusinessThreadState from "./business/BusinessThreadState";
|
|
41
|
+
export abstract class BusinessThreadState<Model=any> extends _BusinessThreadState<Model> {}
|
|
39
42
|
|
|
40
43
|
import BaseBusinessErrors, { ErrorType as _ErrorType, FormalError as _FormalError} from "./business/BusinessErrors";
|
|
41
44
|
export class BusinessErrors extends BaseBusinessErrors {}
|