-
Notifications
You must be signed in to change notification settings - Fork 54
/
TypeormProvider.ts
27 lines (23 loc) · 1.01 KB
/
TypeormProvider.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
import { HealthCheckResponse, Provider } from '@cardano-sdk/core';
import { Logger } from 'ts-log';
import { Observable, skip } from 'rxjs';
import { PgConnectionConfig } from '@cardano-sdk/projection-typeorm';
import { TypeormService } from '../TypeormService';
export interface TypeormProviderDependencies {
logger: Logger;
entities: Function[];
connectionConfig$: Observable<PgConnectionConfig>;
}
export abstract class TypeormProvider extends TypeormService implements Provider {
health: HealthCheckResponse = { ok: false, reason: 'not started' };
constructor(name: string, { connectionConfig$, logger, entities }: TypeormProviderDependencies) {
super(name, { connectionConfig$, entities, logger });
// We skip 1 to omit the initial null value of the subject
this.dataSource$.pipe(skip(1)).subscribe((dataSource) => {
this.health = dataSource ? { ok: true } : { ok: false, reason: 'Provider error' };
});
}
async healthCheck(): Promise<HealthCheckResponse> {
return this.health;
}
}