@saihu/common 1.1.27 → 1.1.29
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/README.md +211 -1
- package/dist/auth/custom-request.d.ts +3 -0
- package/dist/auth/custom-request.d.ts.map +1 -1
- package/dist/auth/decorators.d.ts +4 -0
- package/dist/auth/decorators.d.ts.map +1 -1
- package/dist/auth/decorators.js +8 -1
- package/dist/auth/guards/permission.guard.d.ts +14 -0
- package/dist/auth/guards/permission.guard.d.ts.map +1 -0
- package/dist/auth/guards/permission.guard.js +98 -0
- package/dist/auth/index.d.ts +4 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +6 -0
- package/dist/consts/common.consts.d.ts +8 -0
- package/dist/consts/common.consts.d.ts.map +1 -0
- package/dist/consts/common.consts.js +10 -0
- package/dist/consts/index.d.ts +2 -0
- package/dist/consts/index.d.ts.map +1 -0
- package/dist/consts/index.js +17 -0
- package/dist/dto/index.d.ts +1 -0
- package/dist/dto/index.d.ts.map +1 -1
- package/dist/dto/index.js +1 -0
- package/dist/dto/operlog.dto.d.ts +17 -0
- package/dist/dto/operlog.dto.d.ts.map +1 -0
- package/dist/dto/operlog.dto.js +2 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/interceptors/index.d.ts +1 -0
- package/dist/interceptors/index.d.ts.map +1 -1
- package/dist/interceptors/index.js +1 -0
- package/dist/interceptors/operlog.interceptor.d.ts +21 -0
- package/dist/interceptors/operlog.interceptor.d.ts.map +1 -0
- package/dist/interceptors/operlog.interceptor.js +142 -0
- package/dist/interfaces/options.interface.d.ts +39 -0
- package/dist/interfaces/options.interface.d.ts.map +1 -0
- package/dist/interfaces/options.interface.js +2 -0
- package/dist/interfaces/service.interface.d.ts +11 -0
- package/dist/interfaces/service.interface.d.ts.map +1 -0
- package/dist/interfaces/service.interface.js +2 -0
- package/dist/messaging/bootstrap.d.ts +14 -0
- package/dist/messaging/bootstrap.d.ts.map +1 -0
- package/dist/messaging/bootstrap.js +28 -0
- package/dist/messaging/topology.d.ts +19 -0
- package/dist/messaging/topology.d.ts.map +1 -0
- package/dist/messaging/topology.js +27 -0
- package/dist/saihu-common.module.d.ts +8 -0
- package/dist/saihu-common.module.d.ts.map +1 -0
- package/dist/saihu-common.module.js +101 -0
- package/dist/services/rabbitmq.service.d.ts +18 -0
- package/dist/services/rabbitmq.service.d.ts.map +1 -0
- package/dist/services/rabbitmq.service.js +126 -0
- package/dist/services/redis.service.d.ts +18 -0
- package/dist/services/redis.service.d.ts.map +1 -0
- package/dist/services/redis.service.js +104 -0
- package/package.json +7 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var RedisServiceImpl_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.RedisServiceImpl = void 0;
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
|
22
|
+
const common_consts_1 = require("../consts/common.consts");
|
|
23
|
+
let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
|
|
24
|
+
constructor(commonOptions) {
|
|
25
|
+
this.commonOptions = commonOptions;
|
|
26
|
+
this.logger = new common_1.Logger(RedisServiceImpl_1.name);
|
|
27
|
+
this.isInitialized = false;
|
|
28
|
+
this.isEnabled = false;
|
|
29
|
+
this.isEnabled = commonOptions.usePerms !== false;
|
|
30
|
+
}
|
|
31
|
+
async onModuleInit() {
|
|
32
|
+
await this.initialize();
|
|
33
|
+
}
|
|
34
|
+
async initialize() {
|
|
35
|
+
if (!this.isEnabled) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (this.isInitialized) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if (!this.commonOptions.redis) {
|
|
43
|
+
this.logger.error("common Redis options not found");
|
|
44
|
+
throw new Error("common Redis options not found");
|
|
45
|
+
}
|
|
46
|
+
if (!this.commonOptions.redis.url) {
|
|
47
|
+
this.logger.error("common Redis url not found");
|
|
48
|
+
throw new Error("common Redis url not found");
|
|
49
|
+
}
|
|
50
|
+
if (!this.commonOptions.redis.password) {
|
|
51
|
+
this.logger.error("common Redis password not found");
|
|
52
|
+
throw new Error("common Redis password not found");
|
|
53
|
+
}
|
|
54
|
+
const url = this.commonOptions.redis.url;
|
|
55
|
+
this.logger.log(`common Redis url: ${url}`);
|
|
56
|
+
const password = this.commonOptions.redis.password;
|
|
57
|
+
this.redisClient = new ioredis_1.default(url, {
|
|
58
|
+
password,
|
|
59
|
+
db: common_consts_1.REDIS_AUTH_DB,
|
|
60
|
+
});
|
|
61
|
+
this.logger.log("common Redis connected successfully");
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.logger.error("common Failed to connect to Redis:", error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async get(key) {
|
|
69
|
+
const value = await this.redisClient.get(key);
|
|
70
|
+
if (!value) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(value);
|
|
75
|
+
}
|
|
76
|
+
catch (_a) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async set(key, value, ttl) {
|
|
81
|
+
const serializedValue = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
82
|
+
if (ttl) {
|
|
83
|
+
await this.redisClient.setex(key, ttl, serializedValue);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await this.redisClient.set(key, serializedValue);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async del(key) {
|
|
90
|
+
await this.redisClient.del(key);
|
|
91
|
+
}
|
|
92
|
+
onModuleDestroy() {
|
|
93
|
+
if (!this.isEnabled) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.redisClient.disconnect();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.RedisServiceImpl = RedisServiceImpl;
|
|
100
|
+
exports.RedisServiceImpl = RedisServiceImpl = RedisServiceImpl_1 = __decorate([
|
|
101
|
+
(0, common_1.Injectable)(),
|
|
102
|
+
__param(0, (0, common_1.Inject)(common_consts_1.COMMON_MODULE_OPTIONS)),
|
|
103
|
+
__metadata("design:paramtypes", [Object])
|
|
104
|
+
], RedisServiceImpl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saihu/common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.29",
|
|
4
4
|
"description": "Common utilities for NestJS applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,17 +23,23 @@
|
|
|
23
23
|
"rxjs": "^7.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/amqplib": "^0.10.7",
|
|
26
27
|
"@types/express": "^5.0.1",
|
|
27
28
|
"@types/node": "^22.14.1",
|
|
28
29
|
"typescript": "^5.8.3"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
32
|
+
"@golevelup/nestjs-rabbitmq": "^6.0.2",
|
|
33
|
+
"@nestjs/config": "^4.0.2",
|
|
31
34
|
"@nestjs/core": "^11.1.1",
|
|
32
35
|
"@nestjs/jwt": "^11.0.0",
|
|
36
|
+
"amqp-connection-manager": "^5.0.0",
|
|
37
|
+
"amqplib": "^0.10.9",
|
|
33
38
|
"class-transformer": "^0.5.1",
|
|
34
39
|
"class-validator": "^0.14.2",
|
|
35
40
|
"dayjs": "^1.11.13",
|
|
36
41
|
"express": "^5.1.0",
|
|
42
|
+
"ioredis": "^5.7.0",
|
|
37
43
|
"pinyin-pro": "^3.26.0"
|
|
38
44
|
}
|
|
39
45
|
}
|