@gustavo-valsechi/node 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.js +28 -22
- package/dist/index.mjs +28 -22
- package/dist/src/router/index.js +18 -12
- package/dist/src/router/index.mjs +18 -12
- package/dist/src/server/index.js +17 -11
- package/dist/src/server/index.mjs +17 -11
- package/dist/src/tools/index.js +26 -20
- package/dist/src/tools/index.mjs +26 -20
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -82,25 +82,31 @@ var databaseInit = (entities) => {
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
// src/tools/response.ts
|
|
85
|
+
var import_zod = require("zod");
|
|
85
86
|
var import_utils = __toESM(require("@gustavo-valsechi/utils"));
|
|
87
|
+
var import_lodash = __toESM(require("lodash"));
|
|
86
88
|
var responseWrapper = async (res, promise) => {
|
|
87
89
|
return promise.then(async (data) => {
|
|
88
90
|
res.status(200).send(await import_utils.default.cryptor.encrypt(data));
|
|
89
|
-
}).catch((
|
|
91
|
+
}).catch((error) => {
|
|
90
92
|
var _a;
|
|
91
|
-
const status =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
const status = error.statusCode || 500;
|
|
94
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
95
|
+
if (error instanceof import_zod.ZodError) {
|
|
96
|
+
response = import_lodash.default.reduce(error, (acc, curr) => {
|
|
97
|
+
const field = curr.path.join(".") || "form";
|
|
98
|
+
acc[field] = curr.message;
|
|
99
|
+
return acc;
|
|
100
|
+
}, {});
|
|
101
|
+
}
|
|
102
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
103
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
98
104
|
});
|
|
99
105
|
};
|
|
100
106
|
|
|
101
107
|
// src/tools/operators.ts
|
|
102
108
|
var import_typeorm2 = require("typeorm");
|
|
103
|
-
var
|
|
109
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
104
110
|
var OPERATORS = {
|
|
105
111
|
$in: (value) => (0, import_typeorm2.In)(value),
|
|
106
112
|
$and: (value) => (0, import_typeorm2.And)(value),
|
|
@@ -114,23 +120,23 @@ var OPERATORS = {
|
|
|
114
120
|
$between: ([from, to]) => (0, import_typeorm2.Between)(from, to),
|
|
115
121
|
$not: (value) => (0, import_typeorm2.Not)(value),
|
|
116
122
|
$ne: (value) => (0, import_typeorm2.Not)(value),
|
|
117
|
-
$raw: (value) => (0, import_typeorm2.Raw)((alias) =>
|
|
123
|
+
$raw: (value) => (0, import_typeorm2.Raw)((alias) => import_lodash2.default.replace(value, "ALIAS", alias))
|
|
118
124
|
};
|
|
119
125
|
var existsOperator = (value) => {
|
|
120
126
|
let includeOp = false;
|
|
121
127
|
for (const op in OPERATORS) {
|
|
122
128
|
if (includeOp) continue;
|
|
123
|
-
includeOp =
|
|
129
|
+
includeOp = import_lodash2.default.includes(JSON.stringify(value), op);
|
|
124
130
|
}
|
|
125
131
|
return includeOp;
|
|
126
132
|
};
|
|
127
133
|
var converter = (operator) => {
|
|
128
|
-
operator =
|
|
134
|
+
operator = import_lodash2.default.isObject(operator) ? operator : JSON.parse(operator || "{}");
|
|
129
135
|
let convertion = operator;
|
|
130
136
|
for (const op in OPERATORS) {
|
|
131
137
|
if (!operator[op] && operator[op] !== 0) continue;
|
|
132
|
-
if (
|
|
133
|
-
|
|
138
|
+
if (import_lodash2.default.isObject(operator[op]) && import_lodash2.default.isArray(operator[op])) {
|
|
139
|
+
import_lodash2.default.forEach(operator[op], (condition, index) => {
|
|
134
140
|
if (!existsOperator(condition)) return;
|
|
135
141
|
for (const opSecondary in OPERATORS) {
|
|
136
142
|
if (!condition[opSecondary] && condition[opSecondary] !== 0) continue;
|
|
@@ -147,19 +153,19 @@ var refactorWhere = (where) => {
|
|
|
147
153
|
let includeOp = existsOperator(where[key]);
|
|
148
154
|
if (includeOp) {
|
|
149
155
|
where[key] = converter(where[key]);
|
|
150
|
-
if (
|
|
156
|
+
if (import_lodash2.default.isObject(where[key]) && !import_lodash2.default.isArray(where[key])) {
|
|
151
157
|
for (const keyObject in where[key]) {
|
|
152
158
|
includeOp = existsOperator(where[key][keyObject]);
|
|
153
159
|
if (!includeOp) continue;
|
|
154
160
|
where[key][keyObject] = converter(where[key][keyObject]);
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
|
-
if (
|
|
158
|
-
|
|
163
|
+
if (import_lodash2.default.isObject(where[key]) && import_lodash2.default.isArray(where[key])) {
|
|
164
|
+
import_lodash2.default.forEach(where[key], (condition, index) => {
|
|
159
165
|
includeOp = existsOperator(condition);
|
|
160
166
|
if (includeOp) {
|
|
161
167
|
condition = converter(condition);
|
|
162
|
-
if (
|
|
168
|
+
if (import_lodash2.default.isObject(condition) && !import_lodash2.default.isArray(condition)) {
|
|
163
169
|
for (const keyObject in condition) {
|
|
164
170
|
includeOp = existsOperator(condition[keyObject]);
|
|
165
171
|
if (!includeOp) continue;
|
|
@@ -176,10 +182,10 @@ var refactorWhere = (where) => {
|
|
|
176
182
|
};
|
|
177
183
|
|
|
178
184
|
// src/tools/paginate.ts
|
|
179
|
-
var
|
|
185
|
+
var import_lodash3 = __toESM(require("lodash"));
|
|
180
186
|
var parse = (json) => {
|
|
181
187
|
if (!json) return;
|
|
182
|
-
if (
|
|
188
|
+
if (import_lodash3.default.isString(json)) return JSON.parse(json);
|
|
183
189
|
return json;
|
|
184
190
|
};
|
|
185
191
|
var paginate = async (repository, options) => {
|
|
@@ -280,11 +286,11 @@ var serverInit = (appConfig) => {
|
|
|
280
286
|
};
|
|
281
287
|
|
|
282
288
|
// src/router/api.ts
|
|
283
|
-
var
|
|
289
|
+
var import_lodash4 = __toESM(require("lodash"));
|
|
284
290
|
var apiRouter = (registers) => {
|
|
285
291
|
const apiPrefix = "api";
|
|
286
292
|
app.register((router, options, done) => {
|
|
287
|
-
|
|
293
|
+
import_lodash4.default.forEach(registers, (register, prefix) => {
|
|
288
294
|
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
289
295
|
});
|
|
290
296
|
done();
|
package/dist/index.mjs
CHANGED
|
@@ -41,19 +41,25 @@ var databaseInit = (entities) => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
// src/tools/response.ts
|
|
44
|
+
import { ZodError } from "zod";
|
|
44
45
|
import Utils from "@gustavo-valsechi/utils";
|
|
46
|
+
import _ from "lodash";
|
|
45
47
|
var responseWrapper = async (res, promise) => {
|
|
46
48
|
return promise.then(async (data) => {
|
|
47
49
|
res.status(200).send(await Utils.cryptor.encrypt(data));
|
|
48
|
-
}).catch((
|
|
50
|
+
}).catch((error) => {
|
|
49
51
|
var _a;
|
|
50
|
-
const status =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const status = error.statusCode || 500;
|
|
53
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
54
|
+
if (error instanceof ZodError) {
|
|
55
|
+
response = _.reduce(error, (acc, curr) => {
|
|
56
|
+
const field = curr.path.join(".") || "form";
|
|
57
|
+
acc[field] = curr.message;
|
|
58
|
+
return acc;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
62
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
57
63
|
});
|
|
58
64
|
};
|
|
59
65
|
|
|
@@ -70,7 +76,7 @@ import {
|
|
|
70
76
|
And,
|
|
71
77
|
LessThanOrEqual
|
|
72
78
|
} from "typeorm";
|
|
73
|
-
import
|
|
79
|
+
import _2 from "lodash";
|
|
74
80
|
var OPERATORS = {
|
|
75
81
|
$in: (value) => In(value),
|
|
76
82
|
$and: (value) => And(value),
|
|
@@ -84,23 +90,23 @@ var OPERATORS = {
|
|
|
84
90
|
$between: ([from, to]) => Between(from, to),
|
|
85
91
|
$not: (value) => Not(value),
|
|
86
92
|
$ne: (value) => Not(value),
|
|
87
|
-
$raw: (value) => Raw((alias) =>
|
|
93
|
+
$raw: (value) => Raw((alias) => _2.replace(value, "ALIAS", alias))
|
|
88
94
|
};
|
|
89
95
|
var existsOperator = (value) => {
|
|
90
96
|
let includeOp = false;
|
|
91
97
|
for (const op in OPERATORS) {
|
|
92
98
|
if (includeOp) continue;
|
|
93
|
-
includeOp =
|
|
99
|
+
includeOp = _2.includes(JSON.stringify(value), op);
|
|
94
100
|
}
|
|
95
101
|
return includeOp;
|
|
96
102
|
};
|
|
97
103
|
var converter = (operator) => {
|
|
98
|
-
operator =
|
|
104
|
+
operator = _2.isObject(operator) ? operator : JSON.parse(operator || "{}");
|
|
99
105
|
let convertion = operator;
|
|
100
106
|
for (const op in OPERATORS) {
|
|
101
107
|
if (!operator[op] && operator[op] !== 0) continue;
|
|
102
|
-
if (
|
|
103
|
-
|
|
108
|
+
if (_2.isObject(operator[op]) && _2.isArray(operator[op])) {
|
|
109
|
+
_2.forEach(operator[op], (condition, index) => {
|
|
104
110
|
if (!existsOperator(condition)) return;
|
|
105
111
|
for (const opSecondary in OPERATORS) {
|
|
106
112
|
if (!condition[opSecondary] && condition[opSecondary] !== 0) continue;
|
|
@@ -117,19 +123,19 @@ var refactorWhere = (where) => {
|
|
|
117
123
|
let includeOp = existsOperator(where[key]);
|
|
118
124
|
if (includeOp) {
|
|
119
125
|
where[key] = converter(where[key]);
|
|
120
|
-
if (
|
|
126
|
+
if (_2.isObject(where[key]) && !_2.isArray(where[key])) {
|
|
121
127
|
for (const keyObject in where[key]) {
|
|
122
128
|
includeOp = existsOperator(where[key][keyObject]);
|
|
123
129
|
if (!includeOp) continue;
|
|
124
130
|
where[key][keyObject] = converter(where[key][keyObject]);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
|
-
if (
|
|
128
|
-
|
|
133
|
+
if (_2.isObject(where[key]) && _2.isArray(where[key])) {
|
|
134
|
+
_2.forEach(where[key], (condition, index) => {
|
|
129
135
|
includeOp = existsOperator(condition);
|
|
130
136
|
if (includeOp) {
|
|
131
137
|
condition = converter(condition);
|
|
132
|
-
if (
|
|
138
|
+
if (_2.isObject(condition) && !_2.isArray(condition)) {
|
|
133
139
|
for (const keyObject in condition) {
|
|
134
140
|
includeOp = existsOperator(condition[keyObject]);
|
|
135
141
|
if (!includeOp) continue;
|
|
@@ -146,10 +152,10 @@ var refactorWhere = (where) => {
|
|
|
146
152
|
};
|
|
147
153
|
|
|
148
154
|
// src/tools/paginate.ts
|
|
149
|
-
import
|
|
155
|
+
import _3 from "lodash";
|
|
150
156
|
var parse = (json) => {
|
|
151
157
|
if (!json) return;
|
|
152
|
-
if (
|
|
158
|
+
if (_3.isString(json)) return JSON.parse(json);
|
|
153
159
|
return json;
|
|
154
160
|
};
|
|
155
161
|
var paginate = async (repository, options) => {
|
|
@@ -250,11 +256,11 @@ var serverInit = (appConfig) => {
|
|
|
250
256
|
};
|
|
251
257
|
|
|
252
258
|
// src/router/api.ts
|
|
253
|
-
import
|
|
259
|
+
import _4 from "lodash";
|
|
254
260
|
var apiRouter = (registers) => {
|
|
255
261
|
const apiPrefix = "api";
|
|
256
262
|
app.register((router, options, done) => {
|
|
257
|
-
|
|
263
|
+
_4.forEach(registers, (register, prefix) => {
|
|
258
264
|
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
259
265
|
});
|
|
260
266
|
done();
|
package/dist/src/router/index.js
CHANGED
|
@@ -36,28 +36,34 @@ __export(router_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(router_exports);
|
|
37
37
|
|
|
38
38
|
// src/tools/response.ts
|
|
39
|
+
var import_zod = require("zod");
|
|
39
40
|
var import_utils = __toESM(require("@gustavo-valsechi/utils"));
|
|
41
|
+
var import_lodash = __toESM(require("lodash"));
|
|
40
42
|
var responseWrapper = async (res, promise) => {
|
|
41
43
|
return promise.then(async (data) => {
|
|
42
44
|
res.status(200).send(await import_utils.default.cryptor.encrypt(data));
|
|
43
|
-
}).catch((
|
|
45
|
+
}).catch((error) => {
|
|
44
46
|
var _a;
|
|
45
|
-
const status =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
const status = error.statusCode || 500;
|
|
48
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
49
|
+
if (error instanceof import_zod.ZodError) {
|
|
50
|
+
response = import_lodash.default.reduce(error, (acc, curr) => {
|
|
51
|
+
const field = curr.path.join(".") || "form";
|
|
52
|
+
acc[field] = curr.message;
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
56
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
57
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
52
58
|
});
|
|
53
59
|
};
|
|
54
60
|
|
|
55
61
|
// src/tools/operators.ts
|
|
56
62
|
var import_typeorm = require("typeorm");
|
|
57
|
-
var
|
|
63
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
58
64
|
|
|
59
65
|
// src/tools/paginate.ts
|
|
60
|
-
var
|
|
66
|
+
var import_lodash3 = __toESM(require("lodash"));
|
|
61
67
|
|
|
62
68
|
// src/router/health.ts
|
|
63
69
|
var healthRouter = (router, options, done) => {
|
|
@@ -80,11 +86,11 @@ var import_cors = __toESM(require("@fastify/cors"));
|
|
|
80
86
|
var app = (0, import_fastify.default)();
|
|
81
87
|
|
|
82
88
|
// src/router/api.ts
|
|
83
|
-
var
|
|
89
|
+
var import_lodash4 = __toESM(require("lodash"));
|
|
84
90
|
var apiRouter = (registers) => {
|
|
85
91
|
const apiPrefix = "api";
|
|
86
92
|
app.register((router, options, done) => {
|
|
87
|
-
|
|
93
|
+
import_lodash4.default.forEach(registers, (register, prefix) => {
|
|
88
94
|
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
89
95
|
});
|
|
90
96
|
done();
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
// src/tools/response.ts
|
|
2
|
+
import { ZodError } from "zod";
|
|
2
3
|
import Utils from "@gustavo-valsechi/utils";
|
|
4
|
+
import _ from "lodash";
|
|
3
5
|
var responseWrapper = async (res, promise) => {
|
|
4
6
|
return promise.then(async (data) => {
|
|
5
7
|
res.status(200).send(await Utils.cryptor.encrypt(data));
|
|
6
|
-
}).catch((
|
|
8
|
+
}).catch((error) => {
|
|
7
9
|
var _a;
|
|
8
|
-
const status =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const status = error.statusCode || 500;
|
|
11
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
12
|
+
if (error instanceof ZodError) {
|
|
13
|
+
response = _.reduce(error, (acc, curr) => {
|
|
14
|
+
const field = curr.path.join(".") || "form";
|
|
15
|
+
acc[field] = curr.message;
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
20
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
15
21
|
});
|
|
16
22
|
};
|
|
17
23
|
|
|
@@ -28,10 +34,10 @@ import {
|
|
|
28
34
|
And,
|
|
29
35
|
LessThanOrEqual
|
|
30
36
|
} from "typeorm";
|
|
31
|
-
import
|
|
37
|
+
import _2 from "lodash";
|
|
32
38
|
|
|
33
39
|
// src/tools/paginate.ts
|
|
34
|
-
import
|
|
40
|
+
import _3 from "lodash";
|
|
35
41
|
|
|
36
42
|
// src/router/health.ts
|
|
37
43
|
var healthRouter = (router, options, done) => {
|
|
@@ -54,11 +60,11 @@ import cors from "@fastify/cors";
|
|
|
54
60
|
var app = fastify();
|
|
55
61
|
|
|
56
62
|
// src/router/api.ts
|
|
57
|
-
import
|
|
63
|
+
import _4 from "lodash";
|
|
58
64
|
var apiRouter = (registers) => {
|
|
59
65
|
const apiPrefix = "api";
|
|
60
66
|
app.register((router, options, done) => {
|
|
61
|
-
|
|
67
|
+
_4.forEach(registers, (register, prefix) => {
|
|
62
68
|
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
63
69
|
});
|
|
64
70
|
done();
|
package/dist/src/server/index.js
CHANGED
|
@@ -37,28 +37,34 @@ module.exports = __toCommonJS(server_exports);
|
|
|
37
37
|
var import_fastify = __toESM(require("fastify"));
|
|
38
38
|
|
|
39
39
|
// src/tools/response.ts
|
|
40
|
+
var import_zod = require("zod");
|
|
40
41
|
var import_utils = __toESM(require("@gustavo-valsechi/utils"));
|
|
42
|
+
var import_lodash = __toESM(require("lodash"));
|
|
41
43
|
var responseWrapper = async (res, promise) => {
|
|
42
44
|
return promise.then(async (data) => {
|
|
43
45
|
res.status(200).send(await import_utils.default.cryptor.encrypt(data));
|
|
44
|
-
}).catch((
|
|
46
|
+
}).catch((error) => {
|
|
45
47
|
var _a;
|
|
46
|
-
const status =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const status = error.statusCode || 500;
|
|
49
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
50
|
+
if (error instanceof import_zod.ZodError) {
|
|
51
|
+
response = import_lodash.default.reduce(error, (acc, curr) => {
|
|
52
|
+
const field = curr.path.join(".") || "form";
|
|
53
|
+
acc[field] = curr.message;
|
|
54
|
+
return acc;
|
|
55
|
+
}, {});
|
|
56
|
+
}
|
|
57
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
58
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
53
59
|
});
|
|
54
60
|
};
|
|
55
61
|
|
|
56
62
|
// src/tools/operators.ts
|
|
57
63
|
var import_typeorm = require("typeorm");
|
|
58
|
-
var
|
|
64
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
59
65
|
|
|
60
66
|
// src/tools/paginate.ts
|
|
61
|
-
var
|
|
67
|
+
var import_lodash3 = __toESM(require("lodash"));
|
|
62
68
|
|
|
63
69
|
// src/router/health.ts
|
|
64
70
|
var healthRouter = (router, options, done) => {
|
|
@@ -74,7 +80,7 @@ var healthRouter = (router, options, done) => {
|
|
|
74
80
|
};
|
|
75
81
|
|
|
76
82
|
// src/router/api.ts
|
|
77
|
-
var
|
|
83
|
+
var import_lodash4 = __toESM(require("lodash"));
|
|
78
84
|
|
|
79
85
|
// src/router/index.ts
|
|
80
86
|
var mainRouter = (router, options, done) => {
|
|
@@ -2,19 +2,25 @@
|
|
|
2
2
|
import fastify from "fastify";
|
|
3
3
|
|
|
4
4
|
// src/tools/response.ts
|
|
5
|
+
import { ZodError } from "zod";
|
|
5
6
|
import Utils from "@gustavo-valsechi/utils";
|
|
7
|
+
import _ from "lodash";
|
|
6
8
|
var responseWrapper = async (res, promise) => {
|
|
7
9
|
return promise.then(async (data) => {
|
|
8
10
|
res.status(200).send(await Utils.cryptor.encrypt(data));
|
|
9
|
-
}).catch((
|
|
11
|
+
}).catch((error) => {
|
|
10
12
|
var _a;
|
|
11
|
-
const status =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const status = error.statusCode || 500;
|
|
14
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
15
|
+
if (error instanceof ZodError) {
|
|
16
|
+
response = _.reduce(error, (acc, curr) => {
|
|
17
|
+
const field = curr.path.join(".") || "form";
|
|
18
|
+
acc[field] = curr.message;
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
}
|
|
22
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
23
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
18
24
|
});
|
|
19
25
|
};
|
|
20
26
|
|
|
@@ -31,10 +37,10 @@ import {
|
|
|
31
37
|
And,
|
|
32
38
|
LessThanOrEqual
|
|
33
39
|
} from "typeorm";
|
|
34
|
-
import
|
|
40
|
+
import _2 from "lodash";
|
|
35
41
|
|
|
36
42
|
// src/tools/paginate.ts
|
|
37
|
-
import
|
|
43
|
+
import _3 from "lodash";
|
|
38
44
|
|
|
39
45
|
// src/router/health.ts
|
|
40
46
|
var healthRouter = (router, options, done) => {
|
|
@@ -50,7 +56,7 @@ var healthRouter = (router, options, done) => {
|
|
|
50
56
|
};
|
|
51
57
|
|
|
52
58
|
// src/router/api.ts
|
|
53
|
-
import
|
|
59
|
+
import _4 from "lodash";
|
|
54
60
|
|
|
55
61
|
// src/router/index.ts
|
|
56
62
|
var mainRouter = (router, options, done) => {
|
package/dist/src/tools/index.js
CHANGED
|
@@ -41,25 +41,31 @@ __export(tools_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(tools_exports);
|
|
42
42
|
|
|
43
43
|
// src/tools/response.ts
|
|
44
|
+
var import_zod = require("zod");
|
|
44
45
|
var import_utils = __toESM(require("@gustavo-valsechi/utils"));
|
|
46
|
+
var import_lodash = __toESM(require("lodash"));
|
|
45
47
|
var responseWrapper = async (res, promise) => {
|
|
46
48
|
return promise.then(async (data) => {
|
|
47
49
|
res.status(200).send(await import_utils.default.cryptor.encrypt(data));
|
|
48
|
-
}).catch((
|
|
50
|
+
}).catch((error) => {
|
|
49
51
|
var _a;
|
|
50
|
-
const status =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const status = error.statusCode || 500;
|
|
53
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
54
|
+
if (error instanceof import_zod.ZodError) {
|
|
55
|
+
response = import_lodash.default.reduce(error, (acc, curr) => {
|
|
56
|
+
const field = curr.path.join(".") || "form";
|
|
57
|
+
acc[field] = curr.message;
|
|
58
|
+
return acc;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
62
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
57
63
|
});
|
|
58
64
|
};
|
|
59
65
|
|
|
60
66
|
// src/tools/operators.ts
|
|
61
67
|
var import_typeorm = require("typeorm");
|
|
62
|
-
var
|
|
68
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
63
69
|
var OPERATORS = {
|
|
64
70
|
$in: (value) => (0, import_typeorm.In)(value),
|
|
65
71
|
$and: (value) => (0, import_typeorm.And)(value),
|
|
@@ -73,23 +79,23 @@ var OPERATORS = {
|
|
|
73
79
|
$between: ([from, to]) => (0, import_typeorm.Between)(from, to),
|
|
74
80
|
$not: (value) => (0, import_typeorm.Not)(value),
|
|
75
81
|
$ne: (value) => (0, import_typeorm.Not)(value),
|
|
76
|
-
$raw: (value) => (0, import_typeorm.Raw)((alias) =>
|
|
82
|
+
$raw: (value) => (0, import_typeorm.Raw)((alias) => import_lodash2.default.replace(value, "ALIAS", alias))
|
|
77
83
|
};
|
|
78
84
|
var existsOperator = (value) => {
|
|
79
85
|
let includeOp = false;
|
|
80
86
|
for (const op in OPERATORS) {
|
|
81
87
|
if (includeOp) continue;
|
|
82
|
-
includeOp =
|
|
88
|
+
includeOp = import_lodash2.default.includes(JSON.stringify(value), op);
|
|
83
89
|
}
|
|
84
90
|
return includeOp;
|
|
85
91
|
};
|
|
86
92
|
var converter = (operator) => {
|
|
87
|
-
operator =
|
|
93
|
+
operator = import_lodash2.default.isObject(operator) ? operator : JSON.parse(operator || "{}");
|
|
88
94
|
let convertion = operator;
|
|
89
95
|
for (const op in OPERATORS) {
|
|
90
96
|
if (!operator[op] && operator[op] !== 0) continue;
|
|
91
|
-
if (
|
|
92
|
-
|
|
97
|
+
if (import_lodash2.default.isObject(operator[op]) && import_lodash2.default.isArray(operator[op])) {
|
|
98
|
+
import_lodash2.default.forEach(operator[op], (condition, index) => {
|
|
93
99
|
if (!existsOperator(condition)) return;
|
|
94
100
|
for (const opSecondary in OPERATORS) {
|
|
95
101
|
if (!condition[opSecondary] && condition[opSecondary] !== 0) continue;
|
|
@@ -106,19 +112,19 @@ var refactorWhere = (where) => {
|
|
|
106
112
|
let includeOp = existsOperator(where[key]);
|
|
107
113
|
if (includeOp) {
|
|
108
114
|
where[key] = converter(where[key]);
|
|
109
|
-
if (
|
|
115
|
+
if (import_lodash2.default.isObject(where[key]) && !import_lodash2.default.isArray(where[key])) {
|
|
110
116
|
for (const keyObject in where[key]) {
|
|
111
117
|
includeOp = existsOperator(where[key][keyObject]);
|
|
112
118
|
if (!includeOp) continue;
|
|
113
119
|
where[key][keyObject] = converter(where[key][keyObject]);
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
|
-
if (
|
|
117
|
-
|
|
122
|
+
if (import_lodash2.default.isObject(where[key]) && import_lodash2.default.isArray(where[key])) {
|
|
123
|
+
import_lodash2.default.forEach(where[key], (condition, index) => {
|
|
118
124
|
includeOp = existsOperator(condition);
|
|
119
125
|
if (includeOp) {
|
|
120
126
|
condition = converter(condition);
|
|
121
|
-
if (
|
|
127
|
+
if (import_lodash2.default.isObject(condition) && !import_lodash2.default.isArray(condition)) {
|
|
122
128
|
for (const keyObject in condition) {
|
|
123
129
|
includeOp = existsOperator(condition[keyObject]);
|
|
124
130
|
if (!includeOp) continue;
|
|
@@ -135,10 +141,10 @@ var refactorWhere = (where) => {
|
|
|
135
141
|
};
|
|
136
142
|
|
|
137
143
|
// src/tools/paginate.ts
|
|
138
|
-
var
|
|
144
|
+
var import_lodash3 = __toESM(require("lodash"));
|
|
139
145
|
var parse = (json) => {
|
|
140
146
|
if (!json) return;
|
|
141
|
-
if (
|
|
147
|
+
if (import_lodash3.default.isString(json)) return JSON.parse(json);
|
|
142
148
|
return json;
|
|
143
149
|
};
|
|
144
150
|
var paginate = async (repository, options) => {
|
package/dist/src/tools/index.mjs
CHANGED
|
@@ -6,19 +6,25 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/tools/response.ts
|
|
9
|
+
import { ZodError } from "zod";
|
|
9
10
|
import Utils from "@gustavo-valsechi/utils";
|
|
11
|
+
import _ from "lodash";
|
|
10
12
|
var responseWrapper = async (res, promise) => {
|
|
11
13
|
return promise.then(async (data) => {
|
|
12
14
|
res.status(200).send(await Utils.cryptor.encrypt(data));
|
|
13
|
-
}).catch((
|
|
15
|
+
}).catch((error) => {
|
|
14
16
|
var _a;
|
|
15
|
-
const status =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const status = error.statusCode || 500;
|
|
18
|
+
let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || error.message || error;
|
|
19
|
+
if (error instanceof ZodError) {
|
|
20
|
+
response = _.reduce(error, (acc, curr) => {
|
|
21
|
+
const field = curr.path.join(".") || "form";
|
|
22
|
+
acc[field] = curr.message;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
}
|
|
26
|
+
console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
|
|
27
|
+
return res.status(status).send({ statusCode: status, code: error.code, response });
|
|
22
28
|
});
|
|
23
29
|
};
|
|
24
30
|
|
|
@@ -35,7 +41,7 @@ import {
|
|
|
35
41
|
And,
|
|
36
42
|
LessThanOrEqual
|
|
37
43
|
} from "typeorm";
|
|
38
|
-
import
|
|
44
|
+
import _2 from "lodash";
|
|
39
45
|
var OPERATORS = {
|
|
40
46
|
$in: (value) => In(value),
|
|
41
47
|
$and: (value) => And(value),
|
|
@@ -49,23 +55,23 @@ var OPERATORS = {
|
|
|
49
55
|
$between: ([from, to]) => Between(from, to),
|
|
50
56
|
$not: (value) => Not(value),
|
|
51
57
|
$ne: (value) => Not(value),
|
|
52
|
-
$raw: (value) => Raw((alias) =>
|
|
58
|
+
$raw: (value) => Raw((alias) => _2.replace(value, "ALIAS", alias))
|
|
53
59
|
};
|
|
54
60
|
var existsOperator = (value) => {
|
|
55
61
|
let includeOp = false;
|
|
56
62
|
for (const op in OPERATORS) {
|
|
57
63
|
if (includeOp) continue;
|
|
58
|
-
includeOp =
|
|
64
|
+
includeOp = _2.includes(JSON.stringify(value), op);
|
|
59
65
|
}
|
|
60
66
|
return includeOp;
|
|
61
67
|
};
|
|
62
68
|
var converter = (operator) => {
|
|
63
|
-
operator =
|
|
69
|
+
operator = _2.isObject(operator) ? operator : JSON.parse(operator || "{}");
|
|
64
70
|
let convertion = operator;
|
|
65
71
|
for (const op in OPERATORS) {
|
|
66
72
|
if (!operator[op] && operator[op] !== 0) continue;
|
|
67
|
-
if (
|
|
68
|
-
|
|
73
|
+
if (_2.isObject(operator[op]) && _2.isArray(operator[op])) {
|
|
74
|
+
_2.forEach(operator[op], (condition, index) => {
|
|
69
75
|
if (!existsOperator(condition)) return;
|
|
70
76
|
for (const opSecondary in OPERATORS) {
|
|
71
77
|
if (!condition[opSecondary] && condition[opSecondary] !== 0) continue;
|
|
@@ -82,19 +88,19 @@ var refactorWhere = (where) => {
|
|
|
82
88
|
let includeOp = existsOperator(where[key]);
|
|
83
89
|
if (includeOp) {
|
|
84
90
|
where[key] = converter(where[key]);
|
|
85
|
-
if (
|
|
91
|
+
if (_2.isObject(where[key]) && !_2.isArray(where[key])) {
|
|
86
92
|
for (const keyObject in where[key]) {
|
|
87
93
|
includeOp = existsOperator(where[key][keyObject]);
|
|
88
94
|
if (!includeOp) continue;
|
|
89
95
|
where[key][keyObject] = converter(where[key][keyObject]);
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
98
|
+
if (_2.isObject(where[key]) && _2.isArray(where[key])) {
|
|
99
|
+
_2.forEach(where[key], (condition, index) => {
|
|
94
100
|
includeOp = existsOperator(condition);
|
|
95
101
|
if (includeOp) {
|
|
96
102
|
condition = converter(condition);
|
|
97
|
-
if (
|
|
103
|
+
if (_2.isObject(condition) && !_2.isArray(condition)) {
|
|
98
104
|
for (const keyObject in condition) {
|
|
99
105
|
includeOp = existsOperator(condition[keyObject]);
|
|
100
106
|
if (!includeOp) continue;
|
|
@@ -111,10 +117,10 @@ var refactorWhere = (where) => {
|
|
|
111
117
|
};
|
|
112
118
|
|
|
113
119
|
// src/tools/paginate.ts
|
|
114
|
-
import
|
|
120
|
+
import _3 from "lodash";
|
|
115
121
|
var parse = (json) => {
|
|
116
122
|
if (!json) return;
|
|
117
|
-
if (
|
|
123
|
+
if (_3.isString(json)) return JSON.parse(json);
|
|
118
124
|
return json;
|
|
119
125
|
};
|
|
120
126
|
var paginate = async (repository, options) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gustavo-valsechi/node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"fastify": "5.6.2",
|
|
19
19
|
"fastify-plugin": "5.1.0",
|
|
20
20
|
"pg": "8.11.5",
|
|
21
|
-
"typeorm": "0.3.26"
|
|
21
|
+
"typeorm": "0.3.26",
|
|
22
|
+
"zod": "4.3.6"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@fastify/cors": "11.2.0",
|
|
@@ -44,7 +45,8 @@
|
|
|
44
45
|
"tsup": "8.5.0",
|
|
45
46
|
"typeorm": "0.3.26",
|
|
46
47
|
"typescript": "5.4.5",
|
|
47
|
-
"vitest": "3.0.5"
|
|
48
|
+
"vitest": "3.0.5",
|
|
49
|
+
"zod": "4.3.6"
|
|
48
50
|
},
|
|
49
51
|
"publishConfig": {
|
|
50
52
|
"access": "public"
|