-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConfigBarrelsStore.ts
executable file
·29 lines (25 loc) · 1.3 KB
/
ConfigBarrelsStore.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
import Store from "../../../common/domain/store/Store";
import { getConfig } from "../../config/util/configUtil";
import BarrelDetailsStoreProvider from "../../../common/domain/zeplinComponent/data/BarrelDetailsStoreProvider";
import BarrelDetails from "../../../common/domain/zeplinComponent/model/BarrelDetails";
import Result from "../../../common/domain/store/Result";
import { flatten } from "../../../common/general/arrayUtil";
import BarrelError from "../../../common/domain/zeplinComponent/model/BarrelError";
export default class ConfigBarrelsStore implements Store<BarrelDetails[], BarrelError> {
public constructor(private path: string) { }
public get = async (): Promise<Result<BarrelDetails[], BarrelError>> => {
const config = getConfig(this.path);
const barrels = config.getValidBarrelsWithTypes();
const results = await Promise.all(
barrels.map(({ id, type }) => BarrelDetailsStoreProvider.get(id, type).get())
);
return {
data: results.filter(result => result.data).map(result => result.data!),
errors: flatten(results.map(result => result.errors))
};
};
public refresh = (): Promise<Result<BarrelDetails[], BarrelError>> => {
BarrelDetailsStoreProvider.clearCache();
return this.get();
};
}