@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 CHANGED
@@ -1,10 +1,11 @@
1
1
  export { databaseInit } from './src/database/index.mjs';
2
2
  export { apiRouter, mainRouter } from './src/router/index.mjs';
3
3
  export { app, serverInit } from './src/server/index.mjs';
4
- export { OPERATORS, converter, existsOperator, moduler, paginate, refactorWhere, responseWrapper } from './src/tools/index.mjs';
4
+ export { OPERATORS, Response, converter, existsOperator, logger, moduler, paginate, refactorWhere } from './src/tools/index.mjs';
5
5
  export { IMiddlewareContract, TenantService } from './src/services/index.mjs';
6
6
  export { OptionsSchema } from './src/schemas/index.mjs';
7
7
  import 'typeorm';
8
8
  import 'fastify';
9
9
  import 'http';
10
10
  import 'zod';
11
+ import 'pino';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export { databaseInit } from './src/database/index.js';
2
2
  export { apiRouter, mainRouter } from './src/router/index.js';
3
3
  export { app, serverInit } from './src/server/index.js';
4
- export { OPERATORS, converter, existsOperator, moduler, paginate, refactorWhere, responseWrapper } from './src/tools/index.js';
4
+ export { OPERATORS, Response, converter, existsOperator, logger, moduler, paginate, refactorWhere } from './src/tools/index.js';
5
5
  export { IMiddlewareContract, TenantService } from './src/services/index.js';
6
6
  export { OptionsSchema } from './src/schemas/index.js';
7
7
  import 'typeorm';
8
8
  import 'fastify';
9
9
  import 'http';
10
10
  import 'zod';
11
+ import 'pino';
package/dist/index.js CHANGED
@@ -32,17 +32,18 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  OPERATORS: () => OPERATORS,
34
34
  OptionsSchema: () => OptionsSchema,
35
+ Response: () => Response,
35
36
  TenantService: () => TenantService,
36
37
  apiRouter: () => apiRouter,
37
38
  app: () => app,
38
39
  converter: () => converter,
39
40
  databaseInit: () => databaseInit,
40
41
  existsOperator: () => existsOperator,
42
+ logger: () => logger,
41
43
  mainRouter: () => mainRouter,
42
44
  moduler: () => moduler,
43
45
  paginate: () => paginate,
44
46
  refactorWhere: () => refactorWhere,
45
- responseWrapper: () => responseWrapper,
46
47
  serverInit: () => serverInit
47
48
  });
48
49
  module.exports = __toCommonJS(index_exports);
@@ -50,78 +51,66 @@ module.exports = __toCommonJS(index_exports);
50
51
  // src/database/index.ts
51
52
  var import_config = require("dotenv/config");
52
53
  var import_os = require("os");
53
- var import_typeorm = require("typeorm");
54
- var databaseInit = (entities, options) => {
55
- const type = process.env.DB_TYPE;
56
- const host = process.env.DB_HOST;
57
- const port = process.env.DB_PORT;
58
- const username = process.env.DB_USERNAME;
59
- const password = process.env.DB_PASSWORD;
60
- const database = process.env.DB_DATABASE;
61
- if (!host) throw new Error("DB_HOST is required!");
62
- if (!port) throw new Error("DB_PORT is required!");
63
- if (!username) throw new Error("DB_USERNAME is required!");
64
- if (!password) throw new Error("DB_PASSWORD is required!");
65
- if (!database) throw new Error("DB_DATABASE is required!");
66
- const DB = new import_typeorm.DataSource({
67
- migrationsRun: false,
68
- logging: "all",
69
- logger: "advanced-console",
70
- migrations: ["src/database/migrations/*.ts"],
71
- ...options || {},
72
- type: type || "postgres",
73
- host,
74
- port: Number(port),
75
- username,
76
- password,
77
- database,
78
- synchronize: false,
79
- applicationName: (0, import_os.hostname)(),
80
- entities
81
- });
82
- DB.initialize().then(() => console.log("\u{1F680} Data Source has been initialized!")).catch((err) => console.error("\u{1F534} Error during Data Source initialization", err));
83
- return DB;
84
- };
85
54
 
86
55
  // src/tools/response.ts
87
56
  var import_zod = require("zod");
88
57
  var import_utils = __toESM(require("@gustavo-valsechi/utils"));
89
58
  var import_lodash = __toESM(require("lodash"));
90
- var responseWrapper = async (res, promise) => {
91
- return promise.then(async (data) => {
92
- res.status(200).send(await import_utils.default.cryptor.encrypt(data));
93
- }).catch((error) => {
59
+ var Response = class {
60
+ constructor(response) {
61
+ this.response = response;
62
+ }
63
+ async wrapper(promise) {
64
+ return promise.then(async (data) => {
65
+ return this.response.status(200).send(await import_utils.default.cryptor.encrypt(data));
66
+ }).catch((error) => {
67
+ logger.error(JSON.stringify(this.setError(error)));
68
+ return this.response.status(error.statusCode || 400).send(this.setError(error));
69
+ });
70
+ }
71
+ setError(error) {
94
72
  var _a;
95
- const status = error.statusCode || 500;
96
- let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || (error == null ? void 0 : error.message) || error;
97
- if (error instanceof import_zod.ZodError) {
98
- response = import_lodash.default.transform(JSON.parse(response || "[]"), (acc, item) => {
99
- var _a2;
100
- acc[(_a2 = item == null ? void 0 : item.path) == null ? void 0 : _a2.join(",")] = (item == null ? void 0 : item.message) || "";
101
- }, {});
73
+ switch (true) {
74
+ case error instanceof import_zod.ZodError:
75
+ return this.setZodError(error);
76
+ default:
77
+ const response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || (error == null ? void 0 : error.message);
78
+ return {
79
+ statusCode: error.statusCode || 400,
80
+ code: error.code,
81
+ response: (error == null ? void 0 : error.isAxiosError) && !response ? "Bad Request" : response || error
82
+ };
102
83
  }
103
- console.error("\u{1F534} Request error", (error == null ? void 0 : error.response) || response);
104
- return res.status(status).send({ statusCode: status, code: error.code, response });
105
- });
84
+ }
85
+ setZodError(error) {
86
+ return {
87
+ statusCode: 400,
88
+ code: "ZOD_VALIDATION",
89
+ response: import_lodash.default.transform(JSON.parse(error || "[]"), (acc, item) => {
90
+ var _a;
91
+ acc[(_a = item == null ? void 0 : item.path) == null ? void 0 : _a.join(",")] = (item == null ? void 0 : item.message) || "";
92
+ }, {})
93
+ };
94
+ }
106
95
  };
107
96
 
108
97
  // src/tools/operators.ts
109
- var import_typeorm2 = require("typeorm");
98
+ var import_typeorm = require("typeorm");
110
99
  var import_lodash2 = __toESM(require("lodash"));
111
100
  var OPERATORS = {
112
- $in: (value) => (0, import_typeorm2.In)(value),
113
- $and: (value) => (0, import_typeorm2.And)(value),
114
- $notIn: (value) => (0, import_typeorm2.Not)((0, import_typeorm2.In)(value)),
115
- $like: (value) => (0, import_typeorm2.Like)(value),
116
- $notLike: (value) => (0, import_typeorm2.Not)((0, import_typeorm2.Like)(value)),
117
- $gt: (value) => (0, import_typeorm2.MoreThan)(value),
118
- $gte: (value) => (0, import_typeorm2.MoreThanOrEqual)(value),
119
- $lt: (value) => (0, import_typeorm2.LessThan)(value),
120
- $lte: (value) => (0, import_typeorm2.LessThanOrEqual)(value),
121
- $between: ([from, to]) => (0, import_typeorm2.Between)(from, to),
122
- $not: (value) => (0, import_typeorm2.Not)(value),
123
- $ne: (value) => (0, import_typeorm2.Not)(value),
124
- $raw: (value) => (0, import_typeorm2.Raw)((alias) => import_lodash2.default.replace(value, "ALIAS", alias))
101
+ $in: (value) => (0, import_typeorm.In)(value),
102
+ $and: (value) => (0, import_typeorm.And)(value),
103
+ $notIn: (value) => (0, import_typeorm.Not)((0, import_typeorm.In)(value)),
104
+ $like: (value) => (0, import_typeorm.Like)(value),
105
+ $notLike: (value) => (0, import_typeorm.Not)((0, import_typeorm.Like)(value)),
106
+ $gt: (value) => (0, import_typeorm.MoreThan)(value),
107
+ $gte: (value) => (0, import_typeorm.MoreThanOrEqual)(value),
108
+ $lt: (value) => (0, import_typeorm.LessThan)(value),
109
+ $lte: (value) => (0, import_typeorm.LessThanOrEqual)(value),
110
+ $between: ([from, to]) => (0, import_typeorm.Between)(from, to),
111
+ $not: (value) => (0, import_typeorm.Not)(value),
112
+ $ne: (value) => (0, import_typeorm.Not)(value),
113
+ $raw: (value) => (0, import_typeorm.Raw)((alias) => import_lodash2.default.replace(value, "ALIAS", alias))
125
114
  };
126
115
  var existsOperator = (value) => {
127
116
  let includeOp = false;
@@ -229,11 +218,58 @@ var moduler = () => {
229
218
  return content;
230
219
  };
231
220
 
221
+ // src/tools/logger.ts
222
+ var import_utils2 = __toESM(require("@gustavo-valsechi/utils"));
223
+ var import_pino = __toESM(require("pino"));
224
+ var logger = (0, import_pino.default)({
225
+ timestamp: () => `,"time":"${import_utils2.default.moment().format("HH:mm:ss")}"`,
226
+ transport: {
227
+ target: "pino-pretty",
228
+ options: {
229
+ colorize: true,
230
+ ignore: "pid,hostname"
231
+ }
232
+ }
233
+ });
234
+
235
+ // src/database/index.ts
236
+ var import_typeorm2 = require("typeorm");
237
+ var databaseInit = (entities, options) => {
238
+ const type = process.env.DB_TYPE;
239
+ const host = process.env.DB_HOST;
240
+ const port = process.env.DB_PORT;
241
+ const username = process.env.DB_USERNAME;
242
+ const password = process.env.DB_PASSWORD;
243
+ const database = process.env.DB_DATABASE;
244
+ if (!host) throw new Error("DB_HOST is required!");
245
+ if (!port) throw new Error("DB_PORT is required!");
246
+ if (!username) throw new Error("DB_USERNAME is required!");
247
+ if (!password) throw new Error("DB_PASSWORD is required!");
248
+ if (!database) throw new Error("DB_DATABASE is required!");
249
+ const DB = new import_typeorm2.DataSource({
250
+ migrationsRun: false,
251
+ logging: "all",
252
+ logger: "advanced-console",
253
+ migrations: ["src/database/migrations/*.ts"],
254
+ ...options || {},
255
+ type: type || "postgres",
256
+ host,
257
+ port: Number(port),
258
+ username,
259
+ password,
260
+ database,
261
+ synchronize: false,
262
+ applicationName: (0, import_os.hostname)(),
263
+ entities
264
+ });
265
+ DB.initialize().then(() => logger.info("\u{1F680} Data Source has been initialized!")).catch((err) => logger.error({ message: "\u{1F534} Error during Data Source initialization", error: err }));
266
+ return DB;
267
+ };
268
+
232
269
  // src/router/health.ts
233
270
  var healthRouter = (router, options, done) => {
234
271
  router.get("/", async (req, res) => {
235
- return responseWrapper(
236
- res,
272
+ return new Response(res).wrapper(
237
273
  new Promise((resolve) => {
238
274
  resolve({ message: "OK" });
239
275
  })
@@ -269,7 +305,7 @@ var serverInit = (appConfig) => {
269
305
  instance.addHook(
270
306
  "onResponse",
271
307
  (req, res, done) => {
272
- console.log(`${res.statusCode < 400 ? "\u2705" : "\u{1F534}"} ${res.statusCode} [${req.method}] - ${req.url}`);
308
+ logger[res.statusCode < 400 ? "info" : "error"](`${res.statusCode} [${req.method}] - ${req.url}`);
273
309
  done();
274
310
  }
275
311
  );
@@ -286,10 +322,10 @@ var serverInit = (appConfig) => {
286
322
  };
287
323
  app.listen(listenOptions, (err, address) => {
288
324
  if (err) {
289
- console.error("\u{1F534} Error in server initialization!", err);
325
+ logger.error({ message: "Error in server initialization!", error: err });
290
326
  process.exit(1);
291
327
  }
292
- console.log(`\u{1F680} Server has been started in ${address}...`);
328
+ logger.info(`\u{1F680} Server has been started in ${address}...`);
293
329
  });
294
330
  return app;
295
331
  };
@@ -357,16 +393,17 @@ var TenantService = class {
357
393
  0 && (module.exports = {
358
394
  OPERATORS,
359
395
  OptionsSchema,
396
+ Response,
360
397
  TenantService,
361
398
  apiRouter,
362
399
  app,
363
400
  converter,
364
401
  databaseInit,
365
402
  existsOperator,
403
+ logger,
366
404
  mainRouter,
367
405
  moduler,
368
406
  paginate,
369
407
  refactorWhere,
370
- responseWrapper,
371
408
  serverInit
372
409
  });
package/dist/index.mjs CHANGED
@@ -8,59 +8,47 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
  // src/database/index.ts
9
9
  import "dotenv/config";
10
10
  import { hostname } from "os";
11
- import { DataSource } from "typeorm";
12
- var databaseInit = (entities, options) => {
13
- const type = process.env.DB_TYPE;
14
- const host = process.env.DB_HOST;
15
- const port = process.env.DB_PORT;
16
- const username = process.env.DB_USERNAME;
17
- const password = process.env.DB_PASSWORD;
18
- const database = process.env.DB_DATABASE;
19
- if (!host) throw new Error("DB_HOST is required!");
20
- if (!port) throw new Error("DB_PORT is required!");
21
- if (!username) throw new Error("DB_USERNAME is required!");
22
- if (!password) throw new Error("DB_PASSWORD is required!");
23
- if (!database) throw new Error("DB_DATABASE is required!");
24
- const DB = new DataSource({
25
- migrationsRun: false,
26
- logging: "all",
27
- logger: "advanced-console",
28
- migrations: ["src/database/migrations/*.ts"],
29
- ...options || {},
30
- type: type || "postgres",
31
- host,
32
- port: Number(port),
33
- username,
34
- password,
35
- database,
36
- synchronize: false,
37
- applicationName: hostname(),
38
- entities
39
- });
40
- DB.initialize().then(() => console.log("\u{1F680} Data Source has been initialized!")).catch((err) => console.error("\u{1F534} Error during Data Source initialization", err));
41
- return DB;
42
- };
43
11
 
44
12
  // src/tools/response.ts
45
13
  import { ZodError } from "zod";
46
14
  import Utils from "@gustavo-valsechi/utils";
47
15
  import _ from "lodash";
48
- var responseWrapper = async (res, promise) => {
49
- return promise.then(async (data) => {
50
- res.status(200).send(await Utils.cryptor.encrypt(data));
51
- }).catch((error) => {
16
+ var Response = class {
17
+ constructor(response) {
18
+ this.response = response;
19
+ }
20
+ async wrapper(promise) {
21
+ return promise.then(async (data) => {
22
+ return this.response.status(200).send(await Utils.cryptor.encrypt(data));
23
+ }).catch((error) => {
24
+ logger.error(JSON.stringify(this.setError(error)));
25
+ return this.response.status(error.statusCode || 400).send(this.setError(error));
26
+ });
27
+ }
28
+ setError(error) {
52
29
  var _a;
53
- const status = error.statusCode || 500;
54
- let response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || (error == null ? void 0 : error.message) || error;
55
- if (error instanceof ZodError) {
56
- response = _.transform(JSON.parse(response || "[]"), (acc, item) => {
57
- var _a2;
58
- acc[(_a2 = item == null ? void 0 : item.path) == null ? void 0 : _a2.join(",")] = (item == null ? void 0 : item.message) || "";
59
- }, {});
30
+ switch (true) {
31
+ case error instanceof ZodError:
32
+ return this.setZodError(error);
33
+ default:
34
+ const response = ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) || (error == null ? void 0 : error.message);
35
+ return {
36
+ statusCode: error.statusCode || 400,
37
+ code: error.code,
38
+ response: (error == null ? void 0 : error.isAxiosError) && !response ? "Bad Request" : response || error
39
+ };
60
40
  }
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 });
63
- });
41
+ }
42
+ setZodError(error) {
43
+ return {
44
+ statusCode: 400,
45
+ code: "ZOD_VALIDATION",
46
+ response: _.transform(JSON.parse(error || "[]"), (acc, item) => {
47
+ var _a;
48
+ acc[(_a = item == null ? void 0 : item.path) == null ? void 0 : _a.join(",")] = (item == null ? void 0 : item.message) || "";
49
+ }, {})
50
+ };
51
+ }
64
52
  };
65
53
 
66
54
  // src/tools/operators.ts
@@ -198,11 +186,58 @@ var moduler = () => {
198
186
  return content;
199
187
  };
200
188
 
189
+ // src/tools/logger.ts
190
+ import Utils2 from "@gustavo-valsechi/utils";
191
+ import pino from "pino";
192
+ var logger = pino({
193
+ timestamp: () => `,"time":"${Utils2.moment().format("HH:mm:ss")}"`,
194
+ transport: {
195
+ target: "pino-pretty",
196
+ options: {
197
+ colorize: true,
198
+ ignore: "pid,hostname"
199
+ }
200
+ }
201
+ });
202
+
203
+ // src/database/index.ts
204
+ import { DataSource } from "typeorm";
205
+ var databaseInit = (entities, options) => {
206
+ const type = process.env.DB_TYPE;
207
+ const host = process.env.DB_HOST;
208
+ const port = process.env.DB_PORT;
209
+ const username = process.env.DB_USERNAME;
210
+ const password = process.env.DB_PASSWORD;
211
+ const database = process.env.DB_DATABASE;
212
+ if (!host) throw new Error("DB_HOST is required!");
213
+ if (!port) throw new Error("DB_PORT is required!");
214
+ if (!username) throw new Error("DB_USERNAME is required!");
215
+ if (!password) throw new Error("DB_PASSWORD is required!");
216
+ if (!database) throw new Error("DB_DATABASE is required!");
217
+ const DB = new DataSource({
218
+ migrationsRun: false,
219
+ logging: "all",
220
+ logger: "advanced-console",
221
+ migrations: ["src/database/migrations/*.ts"],
222
+ ...options || {},
223
+ type: type || "postgres",
224
+ host,
225
+ port: Number(port),
226
+ username,
227
+ password,
228
+ database,
229
+ synchronize: false,
230
+ applicationName: hostname(),
231
+ entities
232
+ });
233
+ DB.initialize().then(() => logger.info("\u{1F680} Data Source has been initialized!")).catch((err) => logger.error({ message: "\u{1F534} Error during Data Source initialization", error: err }));
234
+ return DB;
235
+ };
236
+
201
237
  // src/router/health.ts
202
238
  var healthRouter = (router, options, done) => {
203
239
  router.get("/", async (req, res) => {
204
- return responseWrapper(
205
- res,
240
+ return new Response(res).wrapper(
206
241
  new Promise((resolve) => {
207
242
  resolve({ message: "OK" });
208
243
  })
@@ -238,7 +273,7 @@ var serverInit = (appConfig) => {
238
273
  instance.addHook(
239
274
  "onResponse",
240
275
  (req, res, done) => {
241
- console.log(`${res.statusCode < 400 ? "\u2705" : "\u{1F534}"} ${res.statusCode} [${req.method}] - ${req.url}`);
276
+ logger[res.statusCode < 400 ? "info" : "error"](`${res.statusCode} [${req.method}] - ${req.url}`);
242
277
  done();
243
278
  }
244
279
  );
@@ -255,10 +290,10 @@ var serverInit = (appConfig) => {
255
290
  };
256
291
  app.listen(listenOptions, (err, address) => {
257
292
  if (err) {
258
- console.error("\u{1F534} Error in server initialization!", err);
293
+ logger.error({ message: "Error in server initialization!", error: err });
259
294
  process.exit(1);
260
295
  }
261
- console.log(`\u{1F680} Server has been started in ${address}...`);
296
+ logger.info(`\u{1F680} Server has been started in ${address}...`);
262
297
  });
263
298
  return app;
264
299
  };
@@ -325,16 +360,17 @@ var TenantService = class {
325
360
  export {
326
361
  OPERATORS,
327
362
  OptionsSchema,
363
+ Response,
328
364
  TenantService,
329
365
  apiRouter,
330
366
  app,
331
367
  converter,
332
368
  databaseInit,
333
369
  existsOperator,
370
+ logger,
334
371
  mainRouter,
335
372
  moduler,
336
373
  paginate,
337
374
  refactorWhere,
338
- responseWrapper,
339
375
  serverInit
340
376
  };
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/database/index.ts
@@ -25,7 +35,123 @@ __export(database_exports, {
25
35
  module.exports = __toCommonJS(database_exports);
26
36
  var import_config = require("dotenv/config");
27
37
  var import_os = require("os");
38
+
39
+ // src/tools/response.ts
40
+ var import_zod = require("zod");
41
+ var import_utils = __toESM(require("@gustavo-valsechi/utils"));
42
+ var import_lodash = __toESM(require("lodash"));
43
+
44
+ // src/tools/operators.ts
28
45
  var import_typeorm = require("typeorm");
46
+ var import_lodash2 = __toESM(require("lodash"));
47
+ var OPERATORS = {
48
+ $in: (value) => (0, import_typeorm.In)(value),
49
+ $and: (value) => (0, import_typeorm.And)(value),
50
+ $notIn: (value) => (0, import_typeorm.Not)((0, import_typeorm.In)(value)),
51
+ $like: (value) => (0, import_typeorm.Like)(value),
52
+ $notLike: (value) => (0, import_typeorm.Not)((0, import_typeorm.Like)(value)),
53
+ $gt: (value) => (0, import_typeorm.MoreThan)(value),
54
+ $gte: (value) => (0, import_typeorm.MoreThanOrEqual)(value),
55
+ $lt: (value) => (0, import_typeorm.LessThan)(value),
56
+ $lte: (value) => (0, import_typeorm.LessThanOrEqual)(value),
57
+ $between: ([from, to]) => (0, import_typeorm.Between)(from, to),
58
+ $not: (value) => (0, import_typeorm.Not)(value),
59
+ $ne: (value) => (0, import_typeorm.Not)(value),
60
+ $raw: (value) => (0, import_typeorm.Raw)((alias) => import_lodash2.default.replace(value, "ALIAS", alias))
61
+ };
62
+ var existsOperator = (value) => {
63
+ let includeOp = false;
64
+ for (const op in OPERATORS) {
65
+ if (includeOp) continue;
66
+ includeOp = import_lodash2.default.includes(JSON.stringify(value), op);
67
+ }
68
+ return includeOp;
69
+ };
70
+ var converter = (operator) => {
71
+ operator = import_lodash2.default.isObject(operator) ? operator : JSON.parse(operator || "{}");
72
+ let convertion = operator;
73
+ for (const op in OPERATORS) {
74
+ if (!operator[op] && operator[op] !== 0) continue;
75
+ if (import_lodash2.default.isObject(operator[op]) && import_lodash2.default.isArray(operator[op])) {
76
+ import_lodash2.default.forEach(operator[op], (condition, index) => {
77
+ if (!existsOperator(condition)) return;
78
+ for (const opSecondary in OPERATORS) {
79
+ if (!condition[opSecondary] && condition[opSecondary] !== 0) continue;
80
+ operator[op][index] = OPERATORS[opSecondary](condition[opSecondary]);
81
+ }
82
+ });
83
+ }
84
+ convertion = OPERATORS[op](operator[op]);
85
+ }
86
+ return convertion;
87
+ };
88
+ var refactorWhere = (where) => {
89
+ if (!where) return where;
90
+ for (const key in where) {
91
+ let includeOp = existsOperator(where[key]);
92
+ if (includeOp) {
93
+ where[key] = converter(where[key]);
94
+ if (import_lodash2.default.isObject(where[key]) && !import_lodash2.default.isArray(where[key])) {
95
+ for (const keyObject in where[key]) {
96
+ includeOp = existsOperator(where[key][keyObject]);
97
+ if (!includeOp) continue;
98
+ where[key][keyObject] = converter(where[key][keyObject]);
99
+ }
100
+ }
101
+ if (import_lodash2.default.isObject(where[key]) && import_lodash2.default.isArray(where[key])) {
102
+ import_lodash2.default.forEach(where[key], (condition, index) => {
103
+ includeOp = existsOperator(condition);
104
+ if (includeOp) {
105
+ condition = converter(condition);
106
+ if (import_lodash2.default.isObject(condition) && !import_lodash2.default.isArray(condition)) {
107
+ for (const keyObject in condition) {
108
+ includeOp = existsOperator(condition[keyObject]);
109
+ if (!includeOp) continue;
110
+ condition[keyObject] = converter(condition[keyObject]);
111
+ }
112
+ }
113
+ }
114
+ where[key][index] = condition;
115
+ });
116
+ }
117
+ }
118
+ }
119
+ return where;
120
+ };
121
+
122
+ // src/schemas/options.ts
123
+ var import_zod2 = require("zod");
124
+ var import_lodash3 = __toESM(require("lodash"));
125
+ var parse = (json) => {
126
+ if (!json) return;
127
+ if (import_lodash3.default.isString(json)) return JSON.parse(json);
128
+ return json;
129
+ };
130
+ var OptionsSchema = import_zod2.z.object({
131
+ take: import_zod2.z.number().optional(),
132
+ page: import_zod2.z.number().default(0),
133
+ select: import_zod2.z.array(import_zod2.z.string()).optional(),
134
+ relations: import_zod2.z.array(import_zod2.z.string()).optional(),
135
+ where: import_zod2.z.any().transform((value) => refactorWhere(parse(value))).optional(),
136
+ order: import_zod2.z.any().default({ createdAt: "desc" }).transform((value) => parse(value))
137
+ });
138
+
139
+ // src/tools/logger.ts
140
+ var import_utils2 = __toESM(require("@gustavo-valsechi/utils"));
141
+ var import_pino = __toESM(require("pino"));
142
+ var logger = (0, import_pino.default)({
143
+ timestamp: () => `,"time":"${import_utils2.default.moment().format("HH:mm:ss")}"`,
144
+ transport: {
145
+ target: "pino-pretty",
146
+ options: {
147
+ colorize: true,
148
+ ignore: "pid,hostname"
149
+ }
150
+ }
151
+ });
152
+
153
+ // src/database/index.ts
154
+ var import_typeorm2 = require("typeorm");
29
155
  var databaseInit = (entities, options) => {
30
156
  const type = process.env.DB_TYPE;
31
157
  const host = process.env.DB_HOST;
@@ -38,7 +164,7 @@ var databaseInit = (entities, options) => {
38
164
  if (!username) throw new Error("DB_USERNAME is required!");
39
165
  if (!password) throw new Error("DB_PASSWORD is required!");
40
166
  if (!database) throw new Error("DB_DATABASE is required!");
41
- const DB = new import_typeorm.DataSource({
167
+ const DB = new import_typeorm2.DataSource({
42
168
  migrationsRun: false,
43
169
  logging: "all",
44
170
  logger: "advanced-console",
@@ -54,7 +180,7 @@ var databaseInit = (entities, options) => {
54
180
  applicationName: (0, import_os.hostname)(),
55
181
  entities
56
182
  });
57
- DB.initialize().then(() => console.log("\u{1F680} Data Source has been initialized!")).catch((err) => console.error("\u{1F534} Error during Data Source initialization", err));
183
+ DB.initialize().then(() => logger.info("\u{1F680} Data Source has been initialized!")).catch((err) => logger.error({ message: "\u{1F534} Error during Data Source initialization", error: err }));
58
184
  return DB;
59
185
  };
60
186
  // Annotate the CommonJS export names for ESM import in node: