@seidor-cloud-produtos/orbit-backend-lib 0.0.95 → 0.0.97

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.
@@ -17,6 +17,7 @@ export declare abstract class Cache {
17
17
  del(keyCache: string, options?: MethodOptions): Promise<void>;
18
18
  getKeys(pattern?: string, options?: MethodOptions): Promise<string[] | null>;
19
19
  delBatch(patterns: string[], options?: MethodOptions): Promise<void>;
20
+ flush(): Promise<void>;
20
21
  isRunning(options?: MethodOptions): Promise<any>;
21
22
  close(options?: MethodOptions): Promise<void>;
22
23
  }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cache = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const env_1 = require("../../infra/environment/env");
6
+ const logger_1 = tslib_1.__importDefault(require("../logger"));
5
7
  class Cache {
6
8
  constructor(options) {
7
9
  this.DEFAULT_EXPIRATION_SECONDS = env_1.env.DEFAULT_CACHE_EXPIRATION;
@@ -24,10 +26,7 @@ class Cache {
24
26
  }
25
27
  return;
26
28
  }
27
- if (process.env.NODE_ENV !== 'test') {
28
- console.log('\n');
29
- console.log('💾 Cache Connected');
30
- }
29
+ logger_1.default.debug()?.info('💾 Cache Connected');
31
30
  }
32
31
  async get(keyCache, options) {
33
32
  try {
@@ -85,6 +84,9 @@ class Cache {
85
84
  return;
86
85
  }
87
86
  }
87
+ async flush() {
88
+ return await this.client.flush();
89
+ }
88
90
  async isRunning(options) {
89
91
  try {
90
92
  return await this.client.isRunning();
@@ -97,10 +99,7 @@ class Cache {
97
99
  }
98
100
  }
99
101
  async close(options) {
100
- if (process.env.NODE_ENV !== 'test') {
101
- console.log('\n');
102
- console.log('💾 Cache closed');
103
- }
102
+ logger_1.default.debug()?.info('💾 Cache closed');
104
103
  try {
105
104
  return await this.client.close();
106
105
  }
@@ -6,5 +6,6 @@ export declare abstract class CacheClient {
6
6
  abstract del(keyCache: string): Promise<void>;
7
7
  abstract delBatch(keyCache: string[]): Promise<void>;
8
8
  abstract getKeys(pattern?: string): Promise<string[] | null>;
9
+ abstract flush(): Promise<void>;
9
10
  isRunning(): Promise<any>;
10
11
  }
@@ -0,0 +1,11 @@
1
+ export declare enum LOG_LEVEL {
2
+ debug = "DEBUG",
3
+ info = "INFO"
4
+ }
5
+ export declare class Logger {
6
+ debug(): this | undefined;
7
+ info(info: any): void;
8
+ error(error: any): void;
9
+ }
10
+ declare const logger: Logger;
11
+ export default logger;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = exports.LOG_LEVEL = void 0;
4
+ const env_1 = require("../../infra/environment/env");
5
+ var LOG_LEVEL;
6
+ (function (LOG_LEVEL) {
7
+ LOG_LEVEL["debug"] = "DEBUG";
8
+ LOG_LEVEL["info"] = "INFO";
9
+ })(LOG_LEVEL || (exports.LOG_LEVEL = LOG_LEVEL = {}));
10
+ class Logger {
11
+ debug() {
12
+ if (env_1.env.LOG_LEVEL === LOG_LEVEL.debug)
13
+ return this;
14
+ return undefined;
15
+ }
16
+ info(info) {
17
+ console.info(info);
18
+ }
19
+ error(error) {
20
+ console.error(error);
21
+ }
22
+ }
23
+ exports.Logger = Logger;
24
+ const logger = new Logger();
25
+ exports.default = logger;
@@ -9,6 +9,7 @@ export declare class NodeCache extends CacheClient {
9
9
  delBatch(keyCache: string[]): Promise<void>;
10
10
  getKeys(pattern?: string | undefined): Promise<string[]>;
11
11
  close(): Promise<void>;
12
+ flush(): Promise<void>;
12
13
  }
13
14
  declare const _default: NodeCache;
14
15
  export default _default;
@@ -41,6 +41,9 @@ class NodeCache extends client_1.CacheClient {
41
41
  async close() {
42
42
  this.client.flushAll();
43
43
  }
44
+ async flush() {
45
+ return await this.client.flushAll();
46
+ }
44
47
  }
45
48
  exports.NodeCache = NodeCache;
46
49
  exports.default = new NodeCache();
@@ -11,5 +11,6 @@ export declare class Redis extends CacheClient {
11
11
  del(keyCache: string): Promise<void>;
12
12
  delBatch(keyCache: string[]): Promise<void>;
13
13
  getKeys(pattern?: string | undefined): Promise<string[] | null>;
14
+ flush(): Promise<void>;
14
15
  close(): Promise<void>;
15
16
  }
@@ -54,6 +54,9 @@ class Redis extends client_1.CacheClient {
54
54
  Redis.delayOperation(),
55
55
  ]);
56
56
  }
57
+ async flush() {
58
+ await this.client.flushdb();
59
+ }
57
60
  async close() {
58
61
  await this.client.quit();
59
62
  }
@@ -1,7 +1,9 @@
1
1
  import 'dotenv/config';
2
2
  import { ENVIRONMENT_TYPES } from './environment';
3
+ import { LOG_LEVEL } from '../../application/logger';
3
4
  export declare const env: {
4
5
  NODE_ENV: "test" | "production";
5
6
  CURRENT_ENVIRONMENT: ENVIRONMENT_TYPES;
7
+ LOG_LEVEL: LOG_LEVEL;
6
8
  DEFAULT_CACHE_EXPIRATION: number;
7
9
  };
@@ -4,6 +4,7 @@ exports.env = void 0;
4
4
  require("dotenv/config");
5
5
  const zod_1 = require("zod");
6
6
  const environment_1 = require("./environment");
7
+ const logger_1 = require("../../application/logger");
7
8
  const envSchema = zod_1.z.object({
8
9
  NODE_ENV: zod_1.z.enum(['test', 'production']).default('production'),
9
10
  CURRENT_ENVIRONMENT: zod_1.z
@@ -15,6 +16,7 @@ const envSchema = zod_1.z.object({
15
16
  environment_1.ENVIRONMENT_TYPES.PRODUCTION,
16
17
  ])
17
18
  .default(environment_1.ENVIRONMENT_TYPES.LOCAL),
19
+ LOG_LEVEL: zod_1.z.enum([logger_1.LOG_LEVEL.debug, logger_1.LOG_LEVEL.info]).default(logger_1.LOG_LEVEL.info),
18
20
  DEFAULT_CACHE_EXPIRATION: zod_1.z.number().default(360),
19
21
  });
20
22
  const _env = envSchema.safeParse(process.env);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "0.0.95",
3
+ "version": "0.0.97",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",