@gustavo-valsechi/node 1.0.43 → 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 +105 -68
- package/dist/index.mjs +89 -53
- package/dist/src/database/index.js +128 -2
- package/dist/src/database/index.mjs +128 -1
- package/dist/src/router/index.js +50 -17
- package/dist/src/router/index.mjs +50 -17
- package/dist/src/schemas/index.d.mts +1 -1
- package/dist/src/schemas/index.d.ts +1 -1
- package/dist/src/schemas/index.js +1 -1
- package/dist/src/schemas/index.mjs +1 -1
- package/dist/src/server/index.js +53 -20
- package/dist/src/server/index.mjs +53 -20
- package/dist/src/tools/index.d.mts +11 -2
- package/dist/src/tools/index.d.ts +11 -2
- package/dist/src/tools/index.js +55 -19
- package/dist/src/tools/index.mjs +52 -17
- package/package.json +3 -1
package/dist/src/tools/index.js
CHANGED
|
@@ -31,12 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var tools_exports = {};
|
|
32
32
|
__export(tools_exports, {
|
|
33
33
|
OPERATORS: () => OPERATORS,
|
|
34
|
+
Response: () => Response,
|
|
34
35
|
converter: () => converter,
|
|
35
36
|
existsOperator: () => existsOperator,
|
|
37
|
+
logger: () => logger,
|
|
36
38
|
moduler: () => moduler,
|
|
37
39
|
paginate: () => paginate,
|
|
38
|
-
refactorWhere: () => refactorWhere
|
|
39
|
-
responseWrapper: () => responseWrapper
|
|
40
|
+
refactorWhere: () => refactorWhere
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(tools_exports);
|
|
42
43
|
|
|
@@ -44,22 +45,42 @@ module.exports = __toCommonJS(tools_exports);
|
|
|
44
45
|
var import_zod = require("zod");
|
|
45
46
|
var import_utils = __toESM(require("@gustavo-valsechi/utils"));
|
|
46
47
|
var import_lodash = __toESM(require("lodash"));
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
48
|
+
var Response = class {
|
|
49
|
+
constructor(response) {
|
|
50
|
+
this.response = response;
|
|
51
|
+
}
|
|
52
|
+
async wrapper(promise) {
|
|
53
|
+
return promise.then(async (data) => {
|
|
54
|
+
return this.response.status(200).send(await import_utils.default.cryptor.encrypt(data));
|
|
55
|
+
}).catch((error) => {
|
|
56
|
+
logger.error(JSON.stringify(this.setError(error)));
|
|
57
|
+
return this.response.status(error.statusCode || 400).send(this.setError(error));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
setError(error) {
|
|
51
61
|
var _a;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
switch (true) {
|
|
63
|
+
case error instanceof import_zod.ZodError:
|
|
64
|
+
return this.setZodError(error);
|
|
65
|
+
default:
|
|
66
|
+
const response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || (error == null ? void 0 : error.message);
|
|
67
|
+
return {
|
|
68
|
+
statusCode: error.statusCode || 400,
|
|
69
|
+
code: error.code,
|
|
70
|
+
response: (error == null ? void 0 : error.isAxiosError) && !response ? "Bad Request" : response || error
|
|
71
|
+
};
|
|
59
72
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
}
|
|
74
|
+
setZodError(error) {
|
|
75
|
+
return {
|
|
76
|
+
statusCode: 400,
|
|
77
|
+
code: "ZOD_VALIDATION",
|
|
78
|
+
response: import_lodash.default.transform(JSON.parse(error || "[]"), (acc, item) => {
|
|
79
|
+
var _a;
|
|
80
|
+
acc[(_a = item == null ? void 0 : item.path) == null ? void 0 : _a.join(",")] = (item == null ? void 0 : item.message) || "";
|
|
81
|
+
}, {})
|
|
82
|
+
};
|
|
83
|
+
}
|
|
63
84
|
};
|
|
64
85
|
|
|
65
86
|
// src/tools/operators.ts
|
|
@@ -149,7 +170,7 @@ var parse = (json) => {
|
|
|
149
170
|
return json;
|
|
150
171
|
};
|
|
151
172
|
var OptionsSchema = import_zod2.z.object({
|
|
152
|
-
take: import_zod2.z.number(),
|
|
173
|
+
take: import_zod2.z.number().optional(),
|
|
153
174
|
page: import_zod2.z.number().default(0),
|
|
154
175
|
select: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
155
176
|
relations: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
@@ -185,13 +206,28 @@ var moduler = () => {
|
|
|
185
206
|
});
|
|
186
207
|
return content;
|
|
187
208
|
};
|
|
209
|
+
|
|
210
|
+
// src/tools/logger.ts
|
|
211
|
+
var import_utils2 = __toESM(require("@gustavo-valsechi/utils"));
|
|
212
|
+
var import_pino = __toESM(require("pino"));
|
|
213
|
+
var logger = (0, import_pino.default)({
|
|
214
|
+
timestamp: () => `,"time":"${import_utils2.default.moment().format("HH:mm:ss")}"`,
|
|
215
|
+
transport: {
|
|
216
|
+
target: "pino-pretty",
|
|
217
|
+
options: {
|
|
218
|
+
colorize: true,
|
|
219
|
+
ignore: "pid,hostname"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
188
223
|
// Annotate the CommonJS export names for ESM import in node:
|
|
189
224
|
0 && (module.exports = {
|
|
190
225
|
OPERATORS,
|
|
226
|
+
Response,
|
|
191
227
|
converter,
|
|
192
228
|
existsOperator,
|
|
229
|
+
logger,
|
|
193
230
|
moduler,
|
|
194
231
|
paginate,
|
|
195
|
-
refactorWhere
|
|
196
|
-
responseWrapper
|
|
232
|
+
refactorWhere
|
|
197
233
|
});
|
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
|
|
@@ -125,7 +145,7 @@ var parse = (json) => {
|
|
|
125
145
|
return json;
|
|
126
146
|
};
|
|
127
147
|
var OptionsSchema = z.object({
|
|
128
|
-
take: z.number(),
|
|
148
|
+
take: z.number().optional(),
|
|
129
149
|
page: z.number().default(0),
|
|
130
150
|
select: z.array(z.string()).optional(),
|
|
131
151
|
relations: z.array(z.string()).optional(),
|
|
@@ -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": {
|