@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 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((err) => {
91
+ }).catch((error) => {
90
92
  var _a;
91
- const status = err.statusCode || 500;
92
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
93
- return res.status(status).send({
94
- statusCode: status,
95
- code: err.code,
96
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 import_lodash = __toESM(require("lodash"));
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) => import_lodash.default.replace(value, "ALIAS", 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 = import_lodash.default.includes(JSON.stringify(value), op);
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 = import_lodash.default.isObject(operator) ? operator : JSON.parse(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 (import_lodash.default.isObject(operator[op]) && import_lodash.default.isArray(operator[op])) {
133
- import_lodash.default.forEach(operator[op], (condition, index) => {
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 (import_lodash.default.isObject(where[key]) && !import_lodash.default.isArray(where[key])) {
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 (import_lodash.default.isObject(where[key]) && import_lodash.default.isArray(where[key])) {
158
- import_lodash.default.forEach(where[key], (condition, index) => {
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 (import_lodash.default.isObject(condition) && !import_lodash.default.isArray(condition)) {
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 import_lodash2 = __toESM(require("lodash"));
185
+ var import_lodash3 = __toESM(require("lodash"));
180
186
  var parse = (json) => {
181
187
  if (!json) return;
182
- if (import_lodash2.default.isString(json)) return JSON.parse(json);
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 import_lodash3 = __toESM(require("lodash"));
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
- import_lodash3.default.forEach(registers, (register, prefix) => {
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((err) => {
50
+ }).catch((error) => {
49
51
  var _a;
50
- const status = err.statusCode || 500;
51
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
52
- return res.status(status).send({
53
- statusCode: status,
54
- code: err.code,
55
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 _ from "lodash";
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) => _.replace(value, "ALIAS", 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 = _.includes(JSON.stringify(value), op);
99
+ includeOp = _2.includes(JSON.stringify(value), op);
94
100
  }
95
101
  return includeOp;
96
102
  };
97
103
  var converter = (operator) => {
98
- operator = _.isObject(operator) ? operator : JSON.parse(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 (_.isObject(operator[op]) && _.isArray(operator[op])) {
103
- _.forEach(operator[op], (condition, index) => {
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 (_.isObject(where[key]) && !_.isArray(where[key])) {
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 (_.isObject(where[key]) && _.isArray(where[key])) {
128
- _.forEach(where[key], (condition, index) => {
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 (_.isObject(condition) && !_.isArray(condition)) {
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 _2 from "lodash";
155
+ import _3 from "lodash";
150
156
  var parse = (json) => {
151
157
  if (!json) return;
152
- if (_2.isString(json)) return JSON.parse(json);
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 _3 from "lodash";
259
+ import _4 from "lodash";
254
260
  var apiRouter = (registers) => {
255
261
  const apiPrefix = "api";
256
262
  app.register((router, options, done) => {
257
- _3.forEach(registers, (register, prefix) => {
263
+ _4.forEach(registers, (register, prefix) => {
258
264
  router.register(register, { prefix: `${apiPrefix}/${prefix}` });
259
265
  });
260
266
  done();
@@ -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((err) => {
45
+ }).catch((error) => {
44
46
  var _a;
45
- const status = err.statusCode || 500;
46
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
47
- return res.status(status).send({
48
- statusCode: status,
49
- code: err.code,
50
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 import_lodash = __toESM(require("lodash"));
63
+ var import_lodash2 = __toESM(require("lodash"));
58
64
 
59
65
  // src/tools/paginate.ts
60
- var import_lodash2 = __toESM(require("lodash"));
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 import_lodash3 = __toESM(require("lodash"));
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
- import_lodash3.default.forEach(registers, (register, prefix) => {
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((err) => {
8
+ }).catch((error) => {
7
9
  var _a;
8
- const status = err.statusCode || 500;
9
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
10
- return res.status(status).send({
11
- statusCode: status,
12
- code: err.code,
13
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 _ from "lodash";
37
+ import _2 from "lodash";
32
38
 
33
39
  // src/tools/paginate.ts
34
- import _2 from "lodash";
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 _3 from "lodash";
63
+ import _4 from "lodash";
58
64
  var apiRouter = (registers) => {
59
65
  const apiPrefix = "api";
60
66
  app.register((router, options, done) => {
61
- _3.forEach(registers, (register, prefix) => {
67
+ _4.forEach(registers, (register, prefix) => {
62
68
  router.register(register, { prefix: `${apiPrefix}/${prefix}` });
63
69
  });
64
70
  done();
@@ -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((err) => {
46
+ }).catch((error) => {
45
47
  var _a;
46
- const status = err.statusCode || 500;
47
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
48
- return res.status(status).send({
49
- statusCode: status,
50
- code: err.code,
51
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 import_lodash = __toESM(require("lodash"));
64
+ var import_lodash2 = __toESM(require("lodash"));
59
65
 
60
66
  // src/tools/paginate.ts
61
- var import_lodash2 = __toESM(require("lodash"));
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 import_lodash3 = __toESM(require("lodash"));
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((err) => {
11
+ }).catch((error) => {
10
12
  var _a;
11
- const status = err.statusCode || 500;
12
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
13
- return res.status(status).send({
14
- statusCode: status,
15
- code: err.code,
16
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 _ from "lodash";
40
+ import _2 from "lodash";
35
41
 
36
42
  // src/tools/paginate.ts
37
- import _2 from "lodash";
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 _3 from "lodash";
59
+ import _4 from "lodash";
54
60
 
55
61
  // src/router/index.ts
56
62
  var mainRouter = (router, options, done) => {
@@ -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((err) => {
50
+ }).catch((error) => {
49
51
  var _a;
50
- const status = err.statusCode || 500;
51
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
52
- return res.status(status).send({
53
- statusCode: status,
54
- code: err.code,
55
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 import_lodash = __toESM(require("lodash"));
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) => import_lodash.default.replace(value, "ALIAS", 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 = import_lodash.default.includes(JSON.stringify(value), op);
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 = import_lodash.default.isObject(operator) ? operator : JSON.parse(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 (import_lodash.default.isObject(operator[op]) && import_lodash.default.isArray(operator[op])) {
92
- import_lodash.default.forEach(operator[op], (condition, index) => {
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 (import_lodash.default.isObject(where[key]) && !import_lodash.default.isArray(where[key])) {
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 (import_lodash.default.isObject(where[key]) && import_lodash.default.isArray(where[key])) {
117
- import_lodash.default.forEach(where[key], (condition, index) => {
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 (import_lodash.default.isObject(condition) && !import_lodash.default.isArray(condition)) {
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 import_lodash2 = __toESM(require("lodash"));
144
+ var import_lodash3 = __toESM(require("lodash"));
139
145
  var parse = (json) => {
140
146
  if (!json) return;
141
- if (import_lodash2.default.isString(json)) return JSON.parse(json);
147
+ if (import_lodash3.default.isString(json)) return JSON.parse(json);
142
148
  return json;
143
149
  };
144
150
  var paginate = async (repository, options) => {
@@ -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((err) => {
15
+ }).catch((error) => {
14
16
  var _a;
15
- const status = err.statusCode || 500;
16
- console.error("\u{1F534} Request error", (err == null ? void 0 : err.response) || err);
17
- return res.status(status).send({
18
- statusCode: status,
19
- code: err.code,
20
- response: ((_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) || err.message
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 _ from "lodash";
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) => _.replace(value, "ALIAS", 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 = _.includes(JSON.stringify(value), op);
64
+ includeOp = _2.includes(JSON.stringify(value), op);
59
65
  }
60
66
  return includeOp;
61
67
  };
62
68
  var converter = (operator) => {
63
- operator = _.isObject(operator) ? operator : JSON.parse(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 (_.isObject(operator[op]) && _.isArray(operator[op])) {
68
- _.forEach(operator[op], (condition, index) => {
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 (_.isObject(where[key]) && !_.isArray(where[key])) {
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 (_.isObject(where[key]) && _.isArray(where[key])) {
93
- _.forEach(where[key], (condition, index) => {
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 (_.isObject(condition) && !_.isArray(condition)) {
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 _2 from "lodash";
120
+ import _3 from "lodash";
115
121
  var parse = (json) => {
116
122
  if (!json) return;
117
- if (_2.isString(json)) return JSON.parse(json);
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.26",
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"