-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBaseDataSource.ts
More file actions
43 lines (36 loc) · 1.38 KB
/
BaseDataSource.ts
File metadata and controls
43 lines (36 loc) · 1.38 KB
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
/*
* Copyright (c) Trainline Limited, 2020. All rights reserved.
* See LICENSE.md in the project root for license information.
*/
import normalizeStats from '../helpers/normalizeStats';
import { Stats } from '../types';
export enum DataSourceBranchType {
base = 'base',
head = 'head',
}
export interface DataSource {
getCompilationStats(branchType: DataSourceBranchType, sha: string): Promise<Stats>;
}
/* eslint-disable class-methods-use-this, @typescript-eslint/no-unused-vars */
export default class BaseDataSource implements DataSource {
constructor() {
if (this.constructor === BaseDataSource) {
throw new Error("BaseDataSource is an abstract class and can't be instantiated.");
}
}
getCompilationStats(_branchType: DataSourceBranchType, _sha: string): Promise<Stats> {
throw new Error(
'BaseDataSource cannot be used, please use one of the other data sources or extend this class'
);
}
validateCompilationStats(compilationStats: Stats): void {
const containsRequiredProps = normalizeStats(compilationStats).stats.some((stats: Stats) => {
const { assets, modules } = stats;
return assets?.length && modules?.length;
});
if (!containsRequiredProps) {
throw new Error('Compilation stats do not contain assets and modules properties');
}
}
}
/* eslint-enable class-methods-use-this, @typescript-eslint/no-unused-vars */