@gustavo-valsechi/node 1.0.44 → 1.0.45
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.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +104 -67
- package/dist/index.mjs +88 -52
- package/dist/src/database/index.js +128 -2
- package/dist/src/database/index.mjs +128 -1
- package/dist/src/router/index.js +49 -16
- package/dist/src/router/index.mjs +49 -16
- package/dist/src/server/index.js +52 -19
- package/dist/src/server/index.mjs +52 -19
- package/dist/src/tools/index.d.mts +11 -2
- package/dist/src/tools/index.d.ts +11 -2
- package/dist/src/tools/index.js +54 -18
- package/dist/src/tools/index.mjs +51 -16
- package/package.json +3 -1
package/dist/src/tools/index.mjs
CHANGED
|
@@ -9,22 +9,42 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
import { ZodError } from "zod";
|
|
10
10
|
import Utils from "@gustavo-valsechi/utils";
|
|
11
11
|
import _ from "lodash";
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
12
|
+
var Response = class {
|
|
13
|
+
constructor(response) {
|
|
14
|
+
this.response = response;
|
|
15
|
+
}
|
|
16
|
+
async wrapper(promise) {
|
|
17
|
+
return promise.then(async (data) => {
|
|
18
|
+
return this.response.status(200).send(await Utils.cryptor.encrypt(data));
|
|
19
|
+
}).catch((error) => {
|
|
20
|
+
logger.error(JSON.stringify(this.setError(error)));
|
|
21
|
+
return this.response.status(error.statusCode || 400).send(this.setError(error));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
setError(error) {
|
|
16
25
|
var _a;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
switch (true) {
|
|
27
|
+
case error instanceof ZodError:
|
|
28
|
+
return this.setZodError(error);
|
|
29
|
+
default:
|
|
30
|
+
const response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || (error == null ? void 0 : error.message);
|
|
31
|
+
return {
|
|
32
|
+
statusCode: error.statusCode || 400,
|
|
33
|
+
code: error.code,
|
|
34
|
+
response: (error == null ? void 0 : error.isAxiosError) && !response ? "Bad Request" : response || error
|
|
35
|
+
};
|
|
24
36
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
}
|
|
38
|
+
setZodError(error) {
|
|
39
|
+
return {
|
|
40
|
+
statusCode: 400,
|
|
41
|
+
code: "ZOD_VALIDATION",
|
|
42
|
+
response: _.transform(JSON.parse(error || "[]"), (acc, item) => {
|
|
43
|
+
var _a;
|
|
44
|
+
acc[(_a = item == null ? void 0 : item.path) == null ? void 0 : _a.join(",")] = (item == null ? void 0 : item.message) || "";
|
|
45
|
+
}, {})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
28
48
|
};
|
|
29
49
|
|
|
30
50
|
// src/tools/operators.ts
|
|
@@ -161,12 +181,27 @@ var moduler = () => {
|
|
|
161
181
|
});
|
|
162
182
|
return content;
|
|
163
183
|
};
|
|
184
|
+
|
|
185
|
+
// src/tools/logger.ts
|
|
186
|
+
import Utils2 from "@gustavo-valsechi/utils";
|
|
187
|
+
import pino from "pino";
|
|
188
|
+
var logger = pino({
|
|
189
|
+
timestamp: () => `,"time":"${Utils2.moment().format("HH:mm:ss")}"`,
|
|
190
|
+
transport: {
|
|
191
|
+
target: "pino-pretty",
|
|
192
|
+
options: {
|
|
193
|
+
colorize: true,
|
|
194
|
+
ignore: "pid,hostname"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
164
198
|
export {
|
|
165
199
|
OPERATORS,
|
|
200
|
+
Response,
|
|
166
201
|
converter,
|
|
167
202
|
existsOperator,
|
|
203
|
+
logger,
|
|
168
204
|
moduler,
|
|
169
205
|
paginate,
|
|
170
|
-
refactorWhere
|
|
171
|
-
responseWrapper
|
|
206
|
+
refactorWhere
|
|
172
207
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gustavo-valsechi/node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"body-parser": "2.2.1",
|
|
29
29
|
"dotenv": "16.4.5",
|
|
30
30
|
"lodash": "4.17.21",
|
|
31
|
+
"pino": "^10.3.1",
|
|
32
|
+
"pino-pretty": "^13.1.3",
|
|
31
33
|
"uuid": "9.0.1"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|