@nest-omni/core 4.1.3-14 → 4.1.3-17
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/audit/audit.module.js +7 -0
- package/audit/services/entity-audit.service.js +2 -1
- package/audit/services/manual-audit-log.service.js +2 -2
- package/audit/services/multi-database.service.d.ts +0 -5
- package/audit/services/multi-database.service.js +0 -24
- package/audit/services/transaction-audit.service.js +3 -2
- package/cache/dependencies/db.dependency.d.ts +2 -2
- package/cache/dependencies/db.dependency.js +4 -4
- package/decorators/field.decorators.d.ts +1 -1
- package/http-client/examples/proxy-from-environment.example.d.ts +1 -1
- package/http-client/examples/proxy-from-environment.example.js +18 -19
- package/http-client/services/logging.service.js +2 -3
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +3 -2
- package/setup/bootstrap.setup.d.ts +1 -1
- package/shared/service-registry.module.js +2 -15
- package/shared/services/api-config.service.js +1 -0
- package/validators/is-exists.validator.d.ts +2 -7
- package/validators/is-exists.validator.js +2 -24
- package/validators/is-unique.validator.d.ts +2 -7
- package/validators/is-unique.validator.js +2 -24
- package/transaction/__tests__/mocks.d.ts +0 -9
- package/transaction/__tests__/mocks.js +0 -33
- package/transaction/base-service-transaction.d.ts +0 -99
- package/transaction/base-service-transaction.js +0 -286
- package/transaction/cls-compatibility.service.d.ts +0 -55
- package/transaction/cls-compatibility.service.js +0 -127
- package/transaction/data-source-registry.d.ts +0 -91
- package/transaction/data-source-registry.js +0 -349
- package/transaction/data-source.util.d.ts +0 -142
- package/transaction/data-source.util.js +0 -330
- package/transaction/database-adapter.d.ts +0 -44
- package/transaction/database-adapter.js +0 -240
- package/transaction/decorators/entity-datasource.decorator.d.ts +0 -62
- package/transaction/decorators/entity-datasource.decorator.js +0 -105
- package/transaction/index.d.ts +0 -15
- package/transaction/index.js +0 -68
- package/transaction/logging-transactional.interceptor.d.ts +0 -18
- package/transaction/logging-transactional.interceptor.js +0 -163
- package/transaction/transaction-context.service.d.ts +0 -137
- package/transaction/transaction-context.service.js +0 -411
- package/transaction/transaction-manager.d.ts +0 -230
- package/transaction/transaction-manager.js +0 -1001
- package/transaction/transaction-synchronization.d.ts +0 -171
- package/transaction/transaction-synchronization.js +0 -380
- package/transaction/transaction.errors.d.ts +0 -91
- package/transaction/transaction.errors.js +0 -206
- package/transaction/transaction.module.d.ts +0 -30
- package/transaction/transaction.module.js +0 -98
- package/transaction/transactional.decorator.d.ts +0 -82
- package/transaction/transactional.decorator.js +0 -319
- package/transaction/typeorm-module-wrapper.d.ts +0 -96
- package/transaction/typeorm-module-wrapper.js +0 -197
package/audit/audit.module.js
CHANGED
|
@@ -37,6 +37,9 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
37
37
|
var _a, _b;
|
|
38
38
|
const auditConnectionName = ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.audit) || 'default';
|
|
39
39
|
const monitoredConnections = ((_b = config === null || config === void 0 ? void 0 : config.connections) === null || _b === void 0 ? void 0 : _b.monitored) || ['default'];
|
|
40
|
+
console.log('[AuditModule] auditConnectionName:', auditConnectionName);
|
|
41
|
+
console.log('[AuditModule] monitoredConnections:', monitoredConnections);
|
|
42
|
+
console.log('[AuditModule] config:', JSON.stringify(config === null || config === void 0 ? void 0 : config.connections));
|
|
40
43
|
// 创建多个订阅者提供者,每个监听的数据库连接一个
|
|
41
44
|
const subscriberProviders = monitoredConnections.map((connectionName) => ({
|
|
42
45
|
provide: `AUDIT_SUBSCRIBER_${connectionName}`,
|
|
@@ -134,6 +137,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
134
137
|
services_1.TransactionAuditService,
|
|
135
138
|
services_1.OperationDescriptionService,
|
|
136
139
|
services_1.AuditActionService,
|
|
140
|
+
services_1.ManualAuditLogService,
|
|
137
141
|
interceptors_1.AuditInterceptor,
|
|
138
142
|
interceptors_1.AuditActionInterceptor,
|
|
139
143
|
...subscriberProviders,
|
|
@@ -146,6 +150,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
146
150
|
services_1.TransactionAuditService,
|
|
147
151
|
services_1.OperationDescriptionService,
|
|
148
152
|
services_1.AuditActionService,
|
|
153
|
+
services_1.ManualAuditLogService,
|
|
149
154
|
interceptors_1.AuditInterceptor,
|
|
150
155
|
interceptors_1.AuditActionInterceptor,
|
|
151
156
|
(0, typeorm_1.getRepositoryToken)(entities_1.AuditActionSummaryEntity),
|
|
@@ -262,6 +267,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
262
267
|
services_1.TransactionAuditService,
|
|
263
268
|
services_1.OperationDescriptionService,
|
|
264
269
|
services_1.AuditActionService,
|
|
270
|
+
services_1.ManualAuditLogService,
|
|
265
271
|
interceptors_1.AuditInterceptor,
|
|
266
272
|
interceptors_1.AuditActionInterceptor,
|
|
267
273
|
],
|
|
@@ -273,6 +279,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
273
279
|
services_1.TransactionAuditService,
|
|
274
280
|
services_1.OperationDescriptionService,
|
|
275
281
|
services_1.AuditActionService,
|
|
282
|
+
services_1.ManualAuditLogService,
|
|
276
283
|
interceptors_1.AuditInterceptor,
|
|
277
284
|
interceptors_1.AuditActionInterceptor,
|
|
278
285
|
],
|
|
@@ -33,6 +33,7 @@ const audit_strategy_service_1 = require("./audit-strategy.service");
|
|
|
33
33
|
const multi_database_service_1 = require("./multi-database.service");
|
|
34
34
|
const dto_1 = require("../../common/dto");
|
|
35
35
|
const entity_audit_decorator_1 = require("../decorators/entity-audit.decorator");
|
|
36
|
+
const transaction_1 = require("@nest-omni/transaction");
|
|
36
37
|
/**
|
|
37
38
|
* 实体审计服务
|
|
38
39
|
*/
|
|
@@ -248,7 +249,7 @@ let EntityAuditService = class EntityAuditService {
|
|
|
248
249
|
try {
|
|
249
250
|
// 获取指定的数据库连接
|
|
250
251
|
const connectionName = options.connectionName || 'default';
|
|
251
|
-
const dataSource =
|
|
252
|
+
const dataSource = (0, transaction_1.getDataSource)(connectionName);
|
|
252
253
|
const repository = dataSource.getRepository(entityType);
|
|
253
254
|
// 恢复实体
|
|
254
255
|
const restoreData = Object.assign({}, auditLog.oldValue);
|
|
@@ -292,8 +292,8 @@ let ManualAuditLogService = class ManualAuditLogService {
|
|
|
292
292
|
exports.ManualAuditLogService = ManualAuditLogService;
|
|
293
293
|
exports.ManualAuditLogService = ManualAuditLogService = __decorate([
|
|
294
294
|
(0, common_1.Injectable)(),
|
|
295
|
-
__param(0, (0, typeorm_1.InjectRepository)(entities_1.ManualOperationLogEntity
|
|
296
|
-
__param(1, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity
|
|
295
|
+
__param(0, (0, typeorm_1.InjectRepository)(entities_1.ManualOperationLogEntity)),
|
|
296
|
+
__param(1, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity)),
|
|
297
297
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
298
298
|
typeorm_2.Repository,
|
|
299
299
|
audit_context_service_1.AuditContextService,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DataSource } from 'typeorm';
|
|
2
1
|
import { ModuleRef } from '@nestjs/core';
|
|
3
2
|
/**
|
|
4
3
|
* 多数据库连接管理服务
|
|
@@ -7,10 +6,6 @@ export declare class MultiDatabaseService {
|
|
|
7
6
|
private readonly moduleRef;
|
|
8
7
|
private readonly config?;
|
|
9
8
|
constructor(moduleRef: ModuleRef, config?: any);
|
|
10
|
-
/**
|
|
11
|
-
* 获取指定连接的 DataSource
|
|
12
|
-
*/
|
|
13
|
-
getDataSource(connectionName?: string): Promise<DataSource>;
|
|
14
9
|
/**
|
|
15
10
|
* 获取所有监听的数据库连接
|
|
16
11
|
*/
|
|
@@ -11,19 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
15
|
exports.MultiDatabaseService = void 0;
|
|
25
16
|
const common_1 = require("@nestjs/common");
|
|
26
|
-
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
17
|
const core_1 = require("@nestjs/core");
|
|
28
18
|
/**
|
|
29
19
|
* 多数据库连接管理服务
|
|
@@ -33,20 +23,6 @@ let MultiDatabaseService = class MultiDatabaseService {
|
|
|
33
23
|
this.moduleRef = moduleRef;
|
|
34
24
|
this.config = config;
|
|
35
25
|
}
|
|
36
|
-
/**
|
|
37
|
-
* 获取指定连接的 DataSource
|
|
38
|
-
*/
|
|
39
|
-
getDataSource() {
|
|
40
|
-
return __awaiter(this, arguments, void 0, function* (connectionName = 'default') {
|
|
41
|
-
try {
|
|
42
|
-
const dataSource = this.moduleRef.get((0, typeorm_1.getDataSourceToken)(connectionName), { strict: false });
|
|
43
|
-
return dataSource;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
throw new Error(`Failed to get DataSource for connection: ${connectionName}`);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
26
|
/**
|
|
51
27
|
* 获取所有监听的数据库连接
|
|
52
28
|
*/
|
|
@@ -30,6 +30,7 @@ const enums_1 = require("../enums");
|
|
|
30
30
|
const audit_context_service_1 = require("./audit-context.service");
|
|
31
31
|
const entity_audit_service_1 = require("./entity-audit.service");
|
|
32
32
|
const multi_database_service_1 = require("./multi-database.service");
|
|
33
|
+
const transaction_1 = require("@nest-omni/transaction");
|
|
33
34
|
/**
|
|
34
35
|
* 事务审计服务
|
|
35
36
|
*/
|
|
@@ -140,7 +141,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
140
141
|
let connectionFound = false;
|
|
141
142
|
for (const connectionName of monitoredConnections) {
|
|
142
143
|
try {
|
|
143
|
-
const dataSource =
|
|
144
|
+
const dataSource = (0, transaction_1.getDataSource)(connectionName);
|
|
144
145
|
const metadata = dataSource.getMetadata(entity.entityType);
|
|
145
146
|
if (metadata) {
|
|
146
147
|
if (!grouped[connectionName]) {
|
|
@@ -173,7 +174,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
173
174
|
*/
|
|
174
175
|
rollbackEntitiesInConnection(connectionName, entities) {
|
|
175
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const dataSource =
|
|
177
|
+
const dataSource = (0, transaction_1.getDataSource)(connectionName);
|
|
177
178
|
// 使用事务执行回滚
|
|
178
179
|
yield dataSource.transaction((manager) => __awaiter(this, void 0, void 0, function* () {
|
|
179
180
|
for (const entity of entities) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataSource } from 'typeorm';
|
|
2
|
-
import type { CacheDependency } from '../interfaces
|
|
2
|
+
import type { CacheDependency } from '../interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Options for DbDependency
|
|
5
5
|
*/
|
|
@@ -96,7 +96,7 @@ export declare class DbDependency implements CacheDependency {
|
|
|
96
96
|
static getDataSource(): DataSource | null;
|
|
97
97
|
/**
|
|
98
98
|
* Get DataSource for executing queries
|
|
99
|
-
* Priority: 1. Specific dataSourceName from options, 2. Default from
|
|
99
|
+
* Priority: 1. Specific dataSourceName from options, 2. Default from getDataSourceByName, 3. Fallback
|
|
100
100
|
*/
|
|
101
101
|
private getDataSource;
|
|
102
102
|
getKey(): string;
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DbDependency = void 0;
|
|
13
|
-
const
|
|
13
|
+
const transaction_1 = require("@nest-omni/transaction");
|
|
14
14
|
/**
|
|
15
15
|
* Database-based cache dependency
|
|
16
16
|
*
|
|
@@ -100,13 +100,13 @@ class DbDependency {
|
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Get DataSource for executing queries
|
|
103
|
-
* Priority: 1. Specific dataSourceName from options, 2. Default from
|
|
103
|
+
* Priority: 1. Specific dataSourceName from options, 2. Default from getDataSourceByName, 3. Fallback
|
|
104
104
|
*/
|
|
105
105
|
getDataSource() {
|
|
106
106
|
var _a;
|
|
107
|
-
// Try to get from
|
|
107
|
+
// Try to get from getDataSourceByName first
|
|
108
108
|
const dsName = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.dataSourceName) || DbDependency.defaultDataSourceName;
|
|
109
|
-
const dataSource =
|
|
109
|
+
const dataSource = (0, transaction_1.getDataSource)(dsName);
|
|
110
110
|
if (dataSource) {
|
|
111
111
|
return dataSource;
|
|
112
112
|
}
|
|
@@ -69,7 +69,7 @@ export declare function FQDNFieldOptional(options?: Omit<ApiPropertyOptions, 'ty
|
|
|
69
69
|
export declare function DateField(options?: Omit<ApiPropertyOptions, 'type'> & IDateFieldOptions): PropertyDecorator;
|
|
70
70
|
export declare function DateFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required'> & IDateFieldOptions): PropertyDecorator;
|
|
71
71
|
export declare function IpFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IIPFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
72
|
-
export declare function IpField(options
|
|
72
|
+
export declare function IpField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions & IIPFieldOptions): PropertyDecorator;
|
|
73
73
|
export declare function ObjectField(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
74
74
|
export declare function ObjectFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFieldOptions): PropertyDecorator;
|
|
75
75
|
export declare function TimeZoneField(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
@@ -22,11 +22,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
-
var _a, _b, _c, _d, _e, _f;
|
|
26
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
26
|
exports.environmentVariablesExamples = exports.httpClientModuleConfig = exports.ProxyUtilityExample = exports.DevelopmentProxyExample = exports.EnterpriseProxyExample = exports.MixedProxyExample = exports.NoProxyExample = exports.ProxyWithAuthExample = exports.ProxyFromEnvironmentExample = void 0;
|
|
28
27
|
const common_1 = require("@nestjs/common");
|
|
29
|
-
const
|
|
28
|
+
const __1 = require("../");
|
|
30
29
|
/**
|
|
31
30
|
* 示例 1: 使用环境变量配置代理 (推荐方式)
|
|
32
31
|
*
|
|
@@ -66,7 +65,7 @@ let ProxyFromEnvironmentExample = class ProxyFromEnvironmentExample {
|
|
|
66
65
|
};
|
|
67
66
|
exports.ProxyFromEnvironmentExample = ProxyFromEnvironmentExample;
|
|
68
67
|
__decorate([
|
|
69
|
-
(0,
|
|
68
|
+
(0, __1.HttpUseProxy)({
|
|
70
69
|
enabled: true,
|
|
71
70
|
fromEnvironment: true,
|
|
72
71
|
}),
|
|
@@ -76,7 +75,7 @@ __decorate([
|
|
|
76
75
|
], ProxyFromEnvironmentExample.prototype, "fetchWithProxyFromEnv", null);
|
|
77
76
|
exports.ProxyFromEnvironmentExample = ProxyFromEnvironmentExample = __decorate([
|
|
78
77
|
(0, common_1.Injectable)(),
|
|
79
|
-
__metadata("design:paramtypes", [
|
|
78
|
+
__metadata("design:paramtypes", [__1.HttpClientService])
|
|
80
79
|
], ProxyFromEnvironmentExample);
|
|
81
80
|
/**
|
|
82
81
|
* 示例 2: 带认证的代理环境变量
|
|
@@ -97,7 +96,7 @@ let ProxyWithAuthExample = class ProxyWithAuthExample {
|
|
|
97
96
|
};
|
|
98
97
|
exports.ProxyWithAuthExample = ProxyWithAuthExample;
|
|
99
98
|
__decorate([
|
|
100
|
-
(0,
|
|
99
|
+
(0, __1.HttpUseProxy)({
|
|
101
100
|
enabled: true,
|
|
102
101
|
fromEnvironment: true,
|
|
103
102
|
}),
|
|
@@ -107,7 +106,7 @@ __decorate([
|
|
|
107
106
|
], ProxyWithAuthExample.prototype, "fetchWithAuthenticatedProxy", null);
|
|
108
107
|
exports.ProxyWithAuthExample = ProxyWithAuthExample = __decorate([
|
|
109
108
|
(0, common_1.Injectable)(),
|
|
110
|
-
__metadata("design:paramtypes", [
|
|
109
|
+
__metadata("design:paramtypes", [__1.HttpClientService])
|
|
111
110
|
], ProxyWithAuthExample);
|
|
112
111
|
/**
|
|
113
112
|
* 示例 3: NO_PROXY 使用示例
|
|
@@ -141,7 +140,7 @@ let NoProxyExample = class NoProxyExample {
|
|
|
141
140
|
};
|
|
142
141
|
exports.NoProxyExample = NoProxyExample;
|
|
143
142
|
__decorate([
|
|
144
|
-
(0,
|
|
143
|
+
(0, __1.HttpUseProxy)({
|
|
145
144
|
enabled: true,
|
|
146
145
|
fromEnvironment: true,
|
|
147
146
|
}),
|
|
@@ -150,7 +149,7 @@ __decorate([
|
|
|
150
149
|
__metadata("design:returntype", Promise)
|
|
151
150
|
], NoProxyExample.prototype, "fetchExternalApi", null);
|
|
152
151
|
__decorate([
|
|
153
|
-
(0,
|
|
152
|
+
(0, __1.HttpUseProxy)({
|
|
154
153
|
enabled: true,
|
|
155
154
|
fromEnvironment: true,
|
|
156
155
|
}),
|
|
@@ -159,7 +158,7 @@ __decorate([
|
|
|
159
158
|
__metadata("design:returntype", Promise)
|
|
160
159
|
], NoProxyExample.prototype, "fetchInternalApi", null);
|
|
161
160
|
__decorate([
|
|
162
|
-
(0,
|
|
161
|
+
(0, __1.HttpUseProxy)({
|
|
163
162
|
enabled: true,
|
|
164
163
|
fromEnvironment: true,
|
|
165
164
|
}),
|
|
@@ -169,7 +168,7 @@ __decorate([
|
|
|
169
168
|
], NoProxyExample.prototype, "fetchLocalhost", null);
|
|
170
169
|
exports.NoProxyExample = NoProxyExample = __decorate([
|
|
171
170
|
(0, common_1.Injectable)(),
|
|
172
|
-
__metadata("design:paramtypes", [
|
|
171
|
+
__metadata("design:paramtypes", [__1.HttpClientService])
|
|
173
172
|
], NoProxyExample);
|
|
174
173
|
/**
|
|
175
174
|
* 示例 4: 混合使用 - 部分请求使用代理,部分不使用
|
|
@@ -193,7 +192,7 @@ let MixedProxyExample = class MixedProxyExample {
|
|
|
193
192
|
};
|
|
194
193
|
exports.MixedProxyExample = MixedProxyExample;
|
|
195
194
|
__decorate([
|
|
196
|
-
(0,
|
|
195
|
+
(0, __1.HttpUseProxy)({
|
|
197
196
|
enabled: true,
|
|
198
197
|
fromEnvironment: true,
|
|
199
198
|
}),
|
|
@@ -203,7 +202,7 @@ __decorate([
|
|
|
203
202
|
], MixedProxyExample.prototype, "fetchWithProxy", null);
|
|
204
203
|
exports.MixedProxyExample = MixedProxyExample = __decorate([
|
|
205
204
|
(0, common_1.Injectable)(),
|
|
206
|
-
__metadata("design:paramtypes", [
|
|
205
|
+
__metadata("design:paramtypes", [__1.HttpClientService])
|
|
207
206
|
], MixedProxyExample);
|
|
208
207
|
/**
|
|
209
208
|
* 示例 5: 企业环境中的实际使用场景
|
|
@@ -248,7 +247,7 @@ let EnterpriseProxyExample = class EnterpriseProxyExample {
|
|
|
248
247
|
};
|
|
249
248
|
exports.EnterpriseProxyExample = EnterpriseProxyExample;
|
|
250
249
|
__decorate([
|
|
251
|
-
(0,
|
|
250
|
+
(0, __1.HttpUseProxy)({
|
|
252
251
|
enabled: true,
|
|
253
252
|
fromEnvironment: true,
|
|
254
253
|
}),
|
|
@@ -257,7 +256,7 @@ __decorate([
|
|
|
257
256
|
__metadata("design:returntype", Promise)
|
|
258
257
|
], EnterpriseProxyExample.prototype, "fetchFromExternalApi", null);
|
|
259
258
|
__decorate([
|
|
260
|
-
(0,
|
|
259
|
+
(0, __1.HttpUseProxy)({
|
|
261
260
|
enabled: true,
|
|
262
261
|
fromEnvironment: true,
|
|
263
262
|
}),
|
|
@@ -266,7 +265,7 @@ __decorate([
|
|
|
266
265
|
__metadata("design:returntype", Promise)
|
|
267
266
|
], EnterpriseProxyExample.prototype, "fetchFromInternalService", null);
|
|
268
267
|
__decorate([
|
|
269
|
-
(0,
|
|
268
|
+
(0, __1.HttpUseProxy)({
|
|
270
269
|
enabled: true,
|
|
271
270
|
fromEnvironment: true,
|
|
272
271
|
}),
|
|
@@ -276,7 +275,7 @@ __decorate([
|
|
|
276
275
|
], EnterpriseProxyExample.prototype, "fetchFromK8sService", null);
|
|
277
276
|
exports.EnterpriseProxyExample = EnterpriseProxyExample = __decorate([
|
|
278
277
|
(0, common_1.Injectable)(),
|
|
279
|
-
__metadata("design:paramtypes", [
|
|
278
|
+
__metadata("design:paramtypes", [__1.HttpClientService])
|
|
280
279
|
], EnterpriseProxyExample);
|
|
281
280
|
/**
|
|
282
281
|
* 示例 6: 开发环境调试代理
|
|
@@ -301,7 +300,7 @@ let DevelopmentProxyExample = class DevelopmentProxyExample {
|
|
|
301
300
|
};
|
|
302
301
|
exports.DevelopmentProxyExample = DevelopmentProxyExample;
|
|
303
302
|
__decorate([
|
|
304
|
-
(0,
|
|
303
|
+
(0, __1.HttpUseProxy)({
|
|
305
304
|
enabled: process.env.NODE_ENV === 'development',
|
|
306
305
|
fromEnvironment: true,
|
|
307
306
|
}),
|
|
@@ -311,7 +310,7 @@ __decorate([
|
|
|
311
310
|
], DevelopmentProxyExample.prototype, "debugRequest", null);
|
|
312
311
|
exports.DevelopmentProxyExample = DevelopmentProxyExample = __decorate([
|
|
313
312
|
(0, common_1.Injectable)(),
|
|
314
|
-
__metadata("design:paramtypes", [
|
|
313
|
+
__metadata("design:paramtypes", [__1.HttpClientService])
|
|
315
314
|
], DevelopmentProxyExample);
|
|
316
315
|
/**
|
|
317
316
|
* 示例 7: 程序化检查代理配置
|
|
@@ -319,7 +318,7 @@ exports.DevelopmentProxyExample = DevelopmentProxyExample = __decorate([
|
|
|
319
318
|
let ProxyUtilityExample = class ProxyUtilityExample {
|
|
320
319
|
checkProxyConfiguration() {
|
|
321
320
|
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
-
const { ProxyEnvironmentParser } = yield Promise.resolve().then(() => require('
|
|
321
|
+
const { ProxyEnvironmentParser } = yield Promise.resolve().then(() => require('../'));
|
|
323
322
|
// 检查是否设置了代理环境变量
|
|
324
323
|
const hasProxy = ProxyEnvironmentParser.hasProxyEnvironment();
|
|
325
324
|
console.log('Has proxy environment:', hasProxy);
|
|
@@ -26,7 +26,6 @@ const http_log_entity_1 = require("../entities/http-log.entity");
|
|
|
26
26
|
const request_id_util_1 = require("../utils/request-id.util");
|
|
27
27
|
const context_extractor_util_1 = require("../utils/context-extractor.util");
|
|
28
28
|
const call_stack_extractor_util_1 = require("../utils/call-stack-extractor.util");
|
|
29
|
-
const transaction_1 = require("../../transaction");
|
|
30
29
|
/**
|
|
31
30
|
* HTTP日志服务
|
|
32
31
|
* 基于Spring Boot的请求日志记录机制,集成现有的ContextProvider
|
|
@@ -106,8 +105,8 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
|
|
|
106
105
|
this.logger.log(logMessage, logData);
|
|
107
106
|
break;
|
|
108
107
|
}
|
|
109
|
-
if (!this.logRepository) {
|
|
110
|
-
this.logRepository =
|
|
108
|
+
if (!this.logRepository && this.dataSource) {
|
|
109
|
+
this.logRepository = this.dataSource.getRepository(loggingOptions.databaseLogging.tableName);
|
|
111
110
|
}
|
|
112
111
|
// 数据库日志记录
|
|
113
112
|
if (databaseLogging && this.logRepository) {
|
package/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from './validators';
|
|
|
11
11
|
export * from './validator-json';
|
|
12
12
|
export * from './helpers';
|
|
13
13
|
export * from './providers';
|
|
14
|
-
export * from './transaction';
|
|
15
14
|
export * from './redis-lock';
|
|
16
15
|
export * from './cache';
|
|
17
16
|
export * from './http-client';
|
|
@@ -20,3 +19,4 @@ export * from './setup';
|
|
|
20
19
|
export * from './health-checker';
|
|
21
20
|
export * from './audit';
|
|
22
21
|
export * from './file-upload';
|
|
22
|
+
export * from '@nest-omni/transaction';
|
package/index.js
CHANGED
|
@@ -28,7 +28,6 @@ __exportStar(require("./validators"), exports);
|
|
|
28
28
|
__exportStar(require("./validator-json"), exports);
|
|
29
29
|
__exportStar(require("./helpers"), exports);
|
|
30
30
|
__exportStar(require("./providers"), exports);
|
|
31
|
-
__exportStar(require("./transaction"), exports);
|
|
32
31
|
// Lock module
|
|
33
32
|
__exportStar(require("./redis-lock"), exports);
|
|
34
33
|
// Cache module
|
|
@@ -45,3 +44,4 @@ __exportStar(require("./health-checker"), exports);
|
|
|
45
44
|
__exportStar(require("./audit"), exports);
|
|
46
45
|
// File upload module
|
|
47
46
|
__exportStar(require("./file-upload"), exports);
|
|
47
|
+
__exportStar(require("@nest-omni/transaction"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-omni/core",
|
|
3
|
-
"version": "4.1.3-
|
|
3
|
+
"version": "4.1.3-17",
|
|
4
4
|
"description": "A comprehensive NestJS framework for building enterprise-grade applications with best practices",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@dataui/crud": "^5.3.4",
|
|
56
56
|
"@dataui/crud-typeorm": "^5.3.4",
|
|
57
|
+
"@nest-omni/transaction": "^1.0.0",
|
|
57
58
|
"@nestjs/bull": "^11.0.4",
|
|
58
59
|
"@nestjs/common": "^11.1.7",
|
|
59
60
|
"@nestjs/config": "^4.0.2",
|
|
@@ -79,6 +80,7 @@
|
|
|
79
80
|
"dotenv": "^17.2.3",
|
|
80
81
|
"express": "^5.1.0",
|
|
81
82
|
"express-session": "^1.18.2",
|
|
83
|
+
"fast-csv": "^5.0.5",
|
|
82
84
|
"hygen": "^6.2.11",
|
|
83
85
|
"ioredis": "^5.8.2",
|
|
84
86
|
"libphonenumber-js": "^1.12.25",
|
|
@@ -98,7 +100,6 @@
|
|
|
98
100
|
"sprintf-js": "^1.1.3",
|
|
99
101
|
"typeorm": "^0.3.27",
|
|
100
102
|
"uuid": "^13.0.0",
|
|
101
|
-
"fast-csv": "^5.0.5",
|
|
102
103
|
"xlsx": "git+https://git.sheetjs.com/sheetjs/sheetjs.git#v0.20.3"
|
|
103
104
|
},
|
|
104
105
|
"peerDependencies": {}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '../common/boilerplate.polyfill';
|
|
2
2
|
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
3
3
|
export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>>;
|
|
@@ -36,7 +36,7 @@ const redis_lock_1 = require("../redis-lock");
|
|
|
36
36
|
const typeorm_2 = require("typeorm");
|
|
37
37
|
const vault_1 = require("../vault");
|
|
38
38
|
const validators_1 = require("../validators");
|
|
39
|
-
const transaction_1 = require("
|
|
39
|
+
const transaction_1 = require("@nest-omni/transaction");
|
|
40
40
|
const providers = [
|
|
41
41
|
services_1.ApiConfigService,
|
|
42
42
|
services_1.GeneratorService,
|
|
@@ -87,25 +87,12 @@ const modules = [
|
|
|
87
87
|
];
|
|
88
88
|
if (services_1.ApiConfigService.toBoolean(process.env.DB_ENABLED, true)) {
|
|
89
89
|
// 1. 首先导入 TransactionModule
|
|
90
|
-
modules.push(transaction_1.TransactionModule.forRoot(
|
|
91
|
-
defaultDataSource: 'default',
|
|
92
|
-
enableDynamicRegistration: true,
|
|
93
|
-
}));
|
|
90
|
+
modules.push(transaction_1.TransactionModule.forRoot());
|
|
94
91
|
// 2. 导入 TypeORM 模块,并在初始化后注册数据源
|
|
95
92
|
modules.push(typeorm_1.TypeOrmModule.forRootAsync({
|
|
96
93
|
inject: [services_1.ApiConfigService],
|
|
97
94
|
useFactory: (config) => config.typeormConfig,
|
|
98
95
|
}));
|
|
99
|
-
// 3. 添加数据源注册服务,在应用启动时注册 DataSource
|
|
100
|
-
providers.push({
|
|
101
|
-
provide: 'DATASOURCE_REGISTRAR',
|
|
102
|
-
useFactory: (dataSource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
-
// 手动注册 default 数据源到 DataSourceUtil
|
|
104
|
-
(0, transaction_1.addDataSource)('default', dataSource, true);
|
|
105
|
-
return dataSource;
|
|
106
|
-
}),
|
|
107
|
-
inject: [typeorm_2.DataSource],
|
|
108
|
-
});
|
|
109
96
|
// 4. 配置 CLS 模块
|
|
110
97
|
modules.push(nestjs_cls_1.ClsModule.forRootAsync({
|
|
111
98
|
imports: [typeorm_1.TypeOrmModule],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ValidationArguments, ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntitySchema, FindOptionsWhere, ObjectType } from 'typeorm';
|
|
3
3
|
export declare class IsExistsValidator implements ValidatorConstraintInterface {
|
|
4
4
|
constructor();
|
|
5
5
|
/**
|
|
@@ -15,11 +15,6 @@ export declare class IsExistsValidator implements ValidatorConstraintInterface {
|
|
|
15
15
|
* 例如:appId -> App, userId -> User
|
|
16
16
|
*/
|
|
17
17
|
private inferEntityNameFromProperty;
|
|
18
|
-
/**
|
|
19
|
-
* 获取数据源
|
|
20
|
-
* 支持多数据源配置,保持向后兼容
|
|
21
|
-
*/
|
|
22
|
-
private getDataSource;
|
|
23
18
|
validate<E>(value: string, args: IExistsValidationArguments<E>): Promise<boolean>;
|
|
24
19
|
defaultMessage(args: ValidationArguments): string;
|
|
25
20
|
}
|
|
@@ -32,7 +27,7 @@ export interface IsExistsOptions {
|
|
|
32
27
|
* 用于多数据源场景,指定使用哪个数据源进行验证
|
|
33
28
|
* 例如:'readonly', 'report', 或直接传入 DataSource 实例
|
|
34
29
|
*/
|
|
35
|
-
dataSource?: string
|
|
30
|
+
dataSource?: string;
|
|
36
31
|
}
|
|
37
32
|
type ExistsValidationConstraints<E> = [
|
|
38
33
|
(ObjectType<E> | EntitySchema<E> | string | (() => ObjectType<E> | EntitySchema<E> | string)),
|
|
@@ -23,8 +23,7 @@ exports.IsExists = IsExists;
|
|
|
23
23
|
const class_validator_1 = require("class-validator");
|
|
24
24
|
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
|
-
const transaction_1 = require("
|
|
27
|
-
const transaction_2 = require("../transaction");
|
|
26
|
+
const transaction_1 = require("@nest-omni/transaction");
|
|
28
27
|
let IsExistsValidator = class IsExistsValidator {
|
|
29
28
|
constructor() { }
|
|
30
29
|
/**
|
|
@@ -85,27 +84,6 @@ let IsExistsValidator = class IsExistsValidator {
|
|
|
85
84
|
const entityName = name.charAt(0).toUpperCase() + name.slice(1) + 'Entity';
|
|
86
85
|
return entityName;
|
|
87
86
|
}
|
|
88
|
-
/**
|
|
89
|
-
* 获取数据源
|
|
90
|
-
* 支持多数据源配置,保持向后兼容
|
|
91
|
-
*/
|
|
92
|
-
getDataSource(dataSourceOrName) {
|
|
93
|
-
// 1. 如果传入的是 DataSource 实例,直接返回
|
|
94
|
-
if (dataSourceOrName && typeof dataSourceOrName !== 'string') {
|
|
95
|
-
return dataSourceOrName;
|
|
96
|
-
}
|
|
97
|
-
// 2. 如果传入的是数据源名称,获取对应的数据源
|
|
98
|
-
if (typeof dataSourceOrName === 'string') {
|
|
99
|
-
return (0, transaction_2.getDataSource)(dataSourceOrName);
|
|
100
|
-
}
|
|
101
|
-
// 3. 默认:尝试从请求上下文获取,然后获取 default 数据源
|
|
102
|
-
try {
|
|
103
|
-
return transaction_1.TransactionContextService.getDataSource();
|
|
104
|
-
}
|
|
105
|
-
catch (_a) {
|
|
106
|
-
return (0, transaction_2.getDataSource)('default');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
87
|
validate(value, args) {
|
|
110
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
89
|
const [entityRef, findCondition, options] = args.constraints;
|
|
@@ -113,7 +91,7 @@ let IsExistsValidator = class IsExistsValidator {
|
|
|
113
91
|
const entityClass = this.resolveEntity(entityRef, args.property, args.object);
|
|
114
92
|
// 获取数据源(支持多数据源)
|
|
115
93
|
const dataSourceName = (options === null || options === void 0 ? void 0 : options.dataSource) || 'default';
|
|
116
|
-
const dataSource =
|
|
94
|
+
const dataSource = (0, transaction_1.getDataSource)(dataSourceName);
|
|
117
95
|
const repository = dataSource.getRepository(entityClass);
|
|
118
96
|
args.value = value;
|
|
119
97
|
return ((yield repository.count({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ValidationArguments, ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntitySchema, FindOptionsWhere, ObjectType } from 'typeorm';
|
|
3
3
|
export declare class IsUniqueValidator implements ValidatorConstraintInterface {
|
|
4
4
|
constructor();
|
|
5
5
|
/**
|
|
@@ -15,11 +15,6 @@ export declare class IsUniqueValidator implements ValidatorConstraintInterface {
|
|
|
15
15
|
* 例如:appId -> App, userId -> User
|
|
16
16
|
*/
|
|
17
17
|
private inferEntityNameFromProperty;
|
|
18
|
-
/**
|
|
19
|
-
* 获取数据源
|
|
20
|
-
* 支持多数据源配置,保持向后兼容
|
|
21
|
-
*/
|
|
22
|
-
private getDataSource;
|
|
23
18
|
validate<E>(value: string, args: IUniqueValidationArguments<E>): Promise<boolean>;
|
|
24
19
|
defaultMessage(args: ValidationArguments): string;
|
|
25
20
|
}
|
|
@@ -38,7 +33,7 @@ export interface IsUniqueOptions {
|
|
|
38
33
|
* 用于多数据源场景,指定使用哪个数据源进行验证
|
|
39
34
|
* 例如:'readonly', 'report', 或直接传入 DataSource 实例
|
|
40
35
|
*/
|
|
41
|
-
dataSource?: string
|
|
36
|
+
dataSource?: string;
|
|
42
37
|
}
|
|
43
38
|
type UniqueValidationConstraints<E> = [
|
|
44
39
|
(ObjectType<E> | EntitySchema<E> | string | (() => ObjectType<E> | EntitySchema<E> | string)),
|