-
Notifications
You must be signed in to change notification settings - Fork 50
/
registry.module.ts
66 lines (62 loc) · 2.15 KB
/
registry.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { Global, LoggerService, Module } from '@nestjs/common';
import { ValidatorRegistrySource } from 'common/config';
import { FileSourceModule, FileSourceService } from './file-source';
import { KeysapiSourceModule, KeysapiSourceService } from './keysapi-source';
import { LidoSourceModule, LidoSourceService } from './lido-source';
import { REGISTRY_SOURCE, RegistrySource } from './registry-source.interface';
import { RegistryService } from './registry.service';
const selectSource = () => {
switch (process.env['VALIDATOR_REGISTRY_SOURCE']) {
case ValidatorRegistrySource.Lido:
return {
imports: [LidoSourceModule],
providers: [
RegistryService,
{
provide: REGISTRY_SOURCE,
useFactory: async (logger: LoggerService, lido: LidoSourceService): Promise<RegistrySource> => {
// todo: turn on in next major release
// logger.warn('DEPRECATED: VALIDATOR_REGISTRY_SOURCE=lido. Use VALIDATOR_REGISTRY_SOURCE=keysapi instead');
return lido;
},
inject: [LOGGER_PROVIDER, LidoSourceService],
},
],
exports: [RegistryService],
};
case ValidatorRegistrySource.File:
return {
imports: [FileSourceModule],
providers: [
RegistryService,
{
provide: REGISTRY_SOURCE,
useFactory: async (file: FileSourceService): Promise<RegistrySource> => {
return file;
},
inject: [FileSourceService],
},
],
exports: [RegistryService],
};
case ValidatorRegistrySource.KeysAPI:
return {
imports: [KeysapiSourceModule],
providers: [
RegistryService,
{
provide: REGISTRY_SOURCE,
useFactory: async (keysapi: KeysapiSourceService): Promise<RegistrySource> => {
return keysapi;
},
inject: [KeysapiSourceService],
},
],
exports: [RegistryService],
};
}
};
@Global()
@Module(selectSource())
export class RegistryModule {}