@dhedge/backend-flatcoin-core 0.2.92 → 0.2.94
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/entity/multichain-config.d.ts +1 -0
- package/dist/entity/multichain-config.js +4 -0
- package/dist/repository/multichain-config.repository.d.ts +1 -0
- package/dist/repository/multichain-config.repository.js +10 -0
- package/dist/service/multichain-config.service.d.ts +4 -2
- package/dist/service/multichain-config.service.js +18 -9
- package/package.json +1 -1
|
@@ -22,6 +22,10 @@ __decorate([
|
|
|
22
22
|
(0, typeorm_1.Column)({ name: 'blockchain_code', nullable: false }),
|
|
23
23
|
__metadata("design:type", String)
|
|
24
24
|
], MultichainConfig.prototype, "blockchainCode", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.Column)({ name: 'app_name', nullable: false }),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], MultichainConfig.prototype, "appName", void 0);
|
|
25
29
|
__decorate([
|
|
26
30
|
(0, typeorm_1.Column)({ name: 'blockchain_network_name', nullable: false }),
|
|
27
31
|
__metadata("design:type", String)
|
|
@@ -4,4 +4,5 @@ export declare class MultichainConfigRepository {
|
|
|
4
4
|
private repository;
|
|
5
5
|
constructor(repository: Repository<MultichainConfig>);
|
|
6
6
|
getById(id: number): Promise<MultichainConfig | null>;
|
|
7
|
+
getByAppAndCode(appName: string, blockchainCode: string): Promise<MultichainConfig | null>;
|
|
7
8
|
}
|
|
@@ -24,6 +24,16 @@ let MultichainConfigRepository = class MultichainConfigRepository {
|
|
|
24
24
|
async getById(id) {
|
|
25
25
|
return this.repository.createQueryBuilder().where('id = :id').setParameter('id', id).take(1).getOne();
|
|
26
26
|
}
|
|
27
|
+
async getByAppAndCode(appName, blockchainCode) {
|
|
28
|
+
return this.repository
|
|
29
|
+
.createQueryBuilder()
|
|
30
|
+
.where('app_name = :appName')
|
|
31
|
+
.andWhere('blockchain_code = :blockchainCode')
|
|
32
|
+
.setParameter('appName', appName)
|
|
33
|
+
.setParameter('blockchainCode', blockchainCode)
|
|
34
|
+
.take(1)
|
|
35
|
+
.getOne();
|
|
36
|
+
}
|
|
27
37
|
};
|
|
28
38
|
exports.MultichainConfigRepository = MultichainConfigRepository;
|
|
29
39
|
exports.MultichainConfigRepository = MultichainConfigRepository = __decorate([
|
|
@@ -4,7 +4,9 @@ import { MultichainConfig } from '../entity';
|
|
|
4
4
|
export declare class MultichainConfigService {
|
|
5
5
|
private configRepository;
|
|
6
6
|
private readonly logger;
|
|
7
|
-
private
|
|
7
|
+
private readonly configs;
|
|
8
8
|
constructor(configRepository: MultichainConfigRepository, logger: Logger);
|
|
9
|
-
|
|
9
|
+
loadConfigs(appName: string, blockChainCode: string): Promise<MultichainConfig | undefined>;
|
|
10
|
+
private getConfigFromCache;
|
|
11
|
+
private putConfigsToCache;
|
|
10
12
|
}
|
|
@@ -16,25 +16,34 @@ let MultichainConfigService = class MultichainConfigService {
|
|
|
16
16
|
constructor(configRepository, logger) {
|
|
17
17
|
this.configRepository = configRepository;
|
|
18
18
|
this.logger = logger;
|
|
19
|
+
this.configs = new Map();
|
|
19
20
|
}
|
|
20
|
-
async
|
|
21
|
-
if (this.
|
|
22
|
-
return this.
|
|
21
|
+
async loadConfigs(appName, blockChainCode) {
|
|
22
|
+
if (this.getConfigFromCache(appName, blockChainCode)) {
|
|
23
|
+
return this.getConfigFromCache(appName, blockChainCode);
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
|
-
const result = await this.configRepository.
|
|
26
|
+
const result = await this.configRepository.getByAppAndCode(appName, blockChainCode);
|
|
26
27
|
if (!result) {
|
|
27
|
-
throw new Error(
|
|
28
|
+
throw new Error(`failed to load multichain config from db for ${appName} code ${blockChainCode}`);
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
if (!this.
|
|
31
|
-
this.
|
|
32
|
-
this.logger.log(`multichain config loaded from database`);
|
|
31
|
+
if (!this.getConfigFromCache(appName, blockChainCode)) {
|
|
32
|
+
this.putConfigsToCache(appName, blockChainCode, result);
|
|
33
|
+
this.logger.log(`multichain config loaded from database for ${appName} code ${blockChainCode}`);
|
|
33
34
|
}
|
|
34
|
-
return this.
|
|
35
|
+
return this.getConfigFromCache(appName, blockChainCode);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
getConfigFromCache(appName, blockChainCode) {
|
|
40
|
+
const key = appName.concat(blockChainCode);
|
|
41
|
+
return this.configs.get(key);
|
|
42
|
+
}
|
|
43
|
+
putConfigsToCache(appName, blockChainCode, config) {
|
|
44
|
+
const key = appName.concat(blockChainCode);
|
|
45
|
+
this.configs.set(key, config);
|
|
46
|
+
}
|
|
38
47
|
};
|
|
39
48
|
exports.MultichainConfigService = MultichainConfigService;
|
|
40
49
|
exports.MultichainConfigService = MultichainConfigService = __decorate([
|