-
Notifications
You must be signed in to change notification settings - Fork 3
/
SourceReadingSession.ts
45 lines (37 loc) · 1.69 KB
/
SourceReadingSession.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
import { BlockchainSourceType } from './types/IBlockchainSourceSubject';
// import { ListSource } from './mid-level/ListSource';
import { Repository } from '../common/Repository';
import type { IListSource } from './types/IListSource';
import type { IMessage } from '../primitives/IMessage';
import type { ListStorage } from './mid-level/ListStorage';
import type { ListCache } from './mid-level/ListCache';
import type { IBlockchainSourceSubject } from './types/IBlockchainSourceSubject';
export class SourceReadingSession {
public cacheRepository: Repository<IBlockchainSourceSubject, ListCache<IMessage>>;
public storageRepository: Repository<IBlockchainSourceSubject, ListStorage<IMessage>>;
public listSourceRepository: Repository<IBlockchainSourceSubject, IListSource>;
constructor() {
this.cacheRepository = new Repository<IBlockchainSourceSubject, ListCache<IMessage>>(
this.sourceSubjectHash.bind(this),
);
this.storageRepository = new Repository<IBlockchainSourceSubject, ListStorage<IMessage>>(
this.sourceSubjectHash.bind(this),
);
this.listSourceRepository = new Repository<IBlockchainSourceSubject, IListSource>(
this.sourceSubjectHash.bind(this),
);
}
public sourceSubjectHash(k: IBlockchainSourceSubject) {
if (k.type === BlockchainSourceType.BROADCAST) {
return `bc:${k.blockchain}:${k.id}:${k.feedId}:${k.sender || 'null'}`;
} else {
return `dm:${k.blockchain}:${k.id}:${k.recipient}:${k.sender || 'null'}`;
}
}
getListSource(subject: IBlockchainSourceSubject): IListSource | null {
return this.listSourceRepository.get(subject);
}
setListSource(subject: IBlockchainSourceSubject, source: IListSource) {
this.listSourceRepository.set(subject, source);
}
}