-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinconsistent-datapackage.ts
37 lines (30 loc) · 1.48 KB
/
inconsistent-datapackage.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
import * as path from 'path';
import { isEmpty } from 'lodash';
import { DdfDataSet } from '../../ddf-definitions/ddf-data-set';
import { Issue } from '../issue';
import { INCONSISTENT_DATAPACKAGE } from '../registry';
import { DATA_PACKAGE_FILE } from '../../data/data-package';
const isDdfSchemaValid = (dataPackageContent): boolean => {
return dataPackageContent.ddfSchema && (dataPackageContent.ddfSchema.concepts ||
dataPackageContent.ddfSchema.entities || dataPackageContent.ddfSchema.datapoints);
};
export const rule = {
rule: (ddfDataSet: DdfDataSet) => {
const dataPackagePath = path.resolve(ddfDataSet.dataPackageDescriptor.rootFolder, DATA_PACKAGE_FILE);
const consistencyDescriptor = ddfDataSet.dataPackageDescriptor.consistencyDescriptor;
const dataPackageErrors = ddfDataSet.dataPackageDescriptor.errors;
const issues = [];
if (!isEmpty(dataPackageErrors)) {
issues.push(new Issue(INCONSISTENT_DATAPACKAGE).setPath(dataPackagePath).setData(dataPackageErrors));
}
if (!consistencyDescriptor.valid) {
const errors = consistencyDescriptor.errors.map(error => error.message);
issues.push(new Issue(INCONSISTENT_DATAPACKAGE).setPath(dataPackagePath).setData(errors));
}
if (!isDdfSchemaValid(ddfDataSet.dataPackageDescriptor.getDataPackageObject())) {
issues.push(new Issue(INCONSISTENT_DATAPACKAGE)
.setPath(dataPackagePath).setData({reason: 'ddfSchema section is missing or invalid'}))
}
return issues;
}
};