-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathincorrect-fields.ts
34 lines (28 loc) · 1.21 KB
/
incorrect-fields.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
import * as path from 'path';
import { compact, flattenDeep, difference, isEmpty, head } from 'lodash';
import { DATAPACKAGE_INCORRECT_FIELDS } from '../registry';
import { DdfDataSet } from '../../ddf-definitions/ddf-data-set';
import { Issue } from '../issue';
export const rule = {
rule: (ddfDataSet: DdfDataSet) => {
return compact(flattenDeep(
ddfDataSet.getDataPackageResources().map(resource => {
const dataPackageHeaders = resource.schema.fields.map(field => field.name);
const relatedFileDescriptor = head(ddfDataSet.dataPackageDescriptor.fileDescriptors.filter(fileDescriptor =>
fileDescriptor.fullPath === path.resolve(fileDescriptor.rootFolder, resource.path)));
if (!relatedFileDescriptor) {
return null;
}
const realHeaders = relatedFileDescriptor.headers;
const headersDifference = difference(dataPackageHeaders, realHeaders);
let issue = null;
if (!isEmpty(headersDifference)) {
issue = new Issue(DATAPACKAGE_INCORRECT_FIELDS)
.setPath(relatedFileDescriptor.fullPath)
.setData({dataPackageHeaders, realHeaders, headersDifference});
}
return issue;
})
));
}
};