@saihu/common 1.1.48 → 1.1.49

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.ts CHANGED
@@ -7,4 +7,5 @@ export * from './util';
7
7
  export * from './logger';
8
8
  export * from './messaging';
9
9
  export { SaihuCommonModule } from './saihu-common.module';
10
+ export { BaseService } from './services/base.service';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SaihuCommonModule = void 0;
17
+ exports.BaseService = exports.SaihuCommonModule = void 0;
18
18
  __exportStar(require("./dto"), exports);
19
19
  __exportStar(require("./consts"), exports);
20
20
  __exportStar(require("./interceptors"), exports);
@@ -25,3 +25,5 @@ __exportStar(require("./logger"), exports);
25
25
  __exportStar(require("./messaging"), exports);
26
26
  var saihu_common_module_1 = require("./saihu-common.module");
27
27
  Object.defineProperty(exports, "SaihuCommonModule", { enumerable: true, get: function () { return saihu_common_module_1.SaihuCommonModule; } });
28
+ var base_service_1 = require("./services/base.service");
29
+ Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return base_service_1.BaseService; } });
@@ -0,0 +1,7 @@
1
+ import { Logger } from '@nestjs/common';
2
+ export declare abstract class BaseService {
3
+ protected readonly logger: Logger;
4
+ protected readonly loggerError: Logger;
5
+ protected constructor(serviceName: string);
6
+ }
7
+ //# sourceMappingURL=base.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.service.d.ts","sourceRoot":"","sources":["../../src/services/base.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,8BAAsB,WAAW;IAC/B,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAEvC,SAAS,aAAa,WAAW,EAAE,MAAM;CAI1C"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseService = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ class BaseService {
6
+ constructor(serviceName) {
7
+ this.logger = new common_1.Logger(serviceName);
8
+ this.loggerError = new common_1.Logger(`SH-ERROR: ${serviceName}`);
9
+ }
10
+ }
11
+ exports.BaseService = BaseService;
@@ -1,6 +1,6 @@
1
- import { OnModuleInit, OnModuleDestroy } from "@nestjs/common";
2
- import { CommonModuleOptions } from "../interfaces/options.interface";
3
- import { RabbitmqService } from "../interfaces/service.interface";
1
+ import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { CommonModuleOptions } from '../interfaces/options.interface';
3
+ import { RabbitmqService } from '../interfaces/service.interface';
4
4
  export declare class RabbitmqServiceImpl implements RabbitmqService, OnModuleInit, OnModuleDestroy {
5
5
  private readonly options;
6
6
  private readonly logger;
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,qBACa,mBACX,YAAW,eAAe,EAAE,YAAY,EAAE,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAIR,OAAO,EAAE,mBAAmB;IAKzC,YAAY;IAMZ,eAAe;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAcrD"}
1
+ {"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAMtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,qBACa,mBACX,YAAW,eAAe,EAAE,YAAY,EAAE,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAIR,OAAO,EAAE,mBAAmB;IAKzC,YAAY;IAMZ,eAAe;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAkBrD"}
@@ -74,21 +74,21 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
74
74
  }
75
75
  try {
76
76
  if (!this.options.rabbitmq) {
77
- this.logger.error("common RabbitMQ options not configured");
78
- throw new Error("common RabbitMQ options not configured");
77
+ this.logger.error('common RabbitMQ options not configured');
78
+ throw new Error('common RabbitMQ options not configured');
79
79
  }
80
80
  if (!this.options.rabbitmq.url) {
81
- this.logger.error("common RabbitMQ url not configured");
82
- throw new Error("common RabbitMQ url not configured");
81
+ this.logger.error('common RabbitMQ url not configured');
82
+ throw new Error('common RabbitMQ url not configured');
83
83
  }
84
84
  const connectionString = this.options.rabbitmq.url;
85
85
  this.connection = await amqp.connect(connectionString);
86
86
  this.channel = await this.connection.createChannel();
87
87
  this.isInitialized = true;
88
- this.logger.log("common RabbitMQ connected successfully");
88
+ // this.logger.log("common RabbitMQ connected successfully");
89
89
  }
90
90
  catch (error) {
91
- this.logger.error("commonFailed to connect to RabbitMQ:", error);
91
+ this.logger.error('commonFailed to connect to RabbitMQ:', error);
92
92
  throw error;
93
93
  }
94
94
  }
@@ -105,7 +105,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
105
105
  }
106
106
  async publishMessage(message) {
107
107
  if (!this.channel) {
108
- this.logger.error("RabbitMQ channel not initialized");
108
+ this.logger.error('RabbitMQ channel not initialized');
109
109
  return false;
110
110
  }
111
111
  try {
@@ -113,7 +113,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
113
113
  return this.channel.publish(common_consts_1.OPER_LOG_EXCHANGE, common_consts_1.OPER_LOG_QUEUE, messageBuffer);
114
114
  }
115
115
  catch (error) {
116
- this.logger.error("Failed to publish message to RabbitMQ:", error);
116
+ this.logger.error('Failed to publish message to RabbitMQ:', error);
117
117
  return false;
118
118
  }
119
119
  }
@@ -1,6 +1,6 @@
1
- import { OnModuleInit, OnModuleDestroy } from "@nestjs/common";
2
- import { CommonModuleOptions } from "../interfaces/options.interface";
3
- import { RedisService } from "../interfaces/service.interface";
1
+ import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { CommonModuleOptions } from '../interfaces/options.interface';
3
+ import { RedisService } from '../interfaces/service.interface';
4
4
  export declare class RedisServiceImpl implements RedisService, OnModuleInit, OnModuleDestroy {
5
5
  private readonly commonOptions;
6
6
  private readonly logger;
@@ -1 +1 @@
1
- {"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/services/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBACa,gBACX,YAAW,YAAY,EAAE,YAAY,EAAE,eAAe;IASpD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAkB;gBAIhB,aAAa,EAAE,mBAAmB;IAK/C,YAAY;IAIZ,UAAU;IAmCV,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,eAAe;CAMhB"}
1
+ {"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/services/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBACa,gBACX,YAAW,YAAY,EAAE,YAAY,EAAE,eAAe;IASpD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAkB;gBAIhB,aAAa,EAAE,mBAAmB;IAK/C,YAAY;IAIZ,UAAU;IAkCV,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,eAAe;CAMhB"}
@@ -40,28 +40,27 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
40
40
  }
41
41
  try {
42
42
  if (!this.commonOptions.redis) {
43
- this.logger.error("common Redis options not found");
44
- throw new Error("common Redis options not found");
43
+ this.logger.error('common Redis options not found');
44
+ throw new Error('common Redis options not found');
45
45
  }
46
46
  if (!this.commonOptions.redis.url) {
47
- this.logger.error("common Redis url not found");
48
- throw new Error("common Redis url not found");
47
+ this.logger.error('common Redis url not found');
48
+ throw new Error('common Redis url not found');
49
49
  }
50
50
  if (!this.commonOptions.redis.password) {
51
- this.logger.error("common Redis password not found");
52
- throw new Error("common Redis password not found");
51
+ this.logger.error('common Redis password not found');
52
+ throw new Error('common Redis password not found');
53
53
  }
54
54
  const url = this.commonOptions.redis.url;
55
- this.logger.log(`common Redis url: ${url}`);
56
55
  const password = this.commonOptions.redis.password;
57
56
  this.redisClient = new ioredis_1.default(url, {
58
57
  password,
59
58
  db: common_consts_1.REDIS_AUTH_DB,
60
59
  });
61
- this.logger.log("common Redis connected successfully");
60
+ // this.logger.log('common Redis connected successfully');
62
61
  }
63
62
  catch (error) {
64
- this.logger.error("common Failed to connect to Redis:", error);
63
+ this.logger.error('common Failed to connect to Redis:', error);
65
64
  throw error;
66
65
  }
67
66
  }
@@ -78,7 +77,7 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
78
77
  }
79
78
  }
80
79
  async set(key, value, ttl) {
81
- const serializedValue = typeof value === "object" ? JSON.stringify(value) : String(value);
80
+ const serializedValue = typeof value === 'object' ? JSON.stringify(value) : String(value);
82
81
  if (ttl) {
83
82
  await this.redisClient.setex(key, ttl, serializedValue);
84
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.48",
3
+ "version": "1.1.49",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",