Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ddf-validation

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ddf-validation - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

5

index.js

@@ -220,7 +220,9 @@ #! /usr/bin/env node

// missing dimension ids
// unexpected dimension ids
const measureValuesChecker = require('./lib/ddf-measure-values.validator');
// 2. check data points
// report missing measure values data points
// like abkh 1983
const measureValuesChecker = require('./lib/ddf-measure-values.validator');
const dataPointsChecker = require('./lib/ddf-data-points.validator');
let options = [

@@ -239,3 +241,2 @@ measureValuesChecker(dimensionsValuesIndex$, measuresData$)

.subscribe(x=>logger.results(x), x=>console.error(x.stack));
})

@@ -242,0 +243,0 @@ .subscribe();

16

lib/ddf-data-points.validator.js

@@ -24,11 +24,9 @@ 'use strict';

// looking for only appropriate dimension value
// for example, for 'country' file we should process only
// dimensions with 'is.country' field === 'TRUE'
if (acc.dimensionsHash[dimKey][measureValue.data[dimKey]]) {
const dimensionTypeByMeasure =
acc.dimensionsHash[dimKey][measureValue.data[dimKey]][shared.getDimensionType(acc.fileName)];
if (dimensionTypeByMeasure.toLowerCase() !== 'true') {
return;
}
if (shared
.isExpectedDimension(
acc.fileName,
acc.dimensionsHash,
dimKey,
measureValue.data[dimKey]) === false) {
return;
}

@@ -35,0 +33,0 @@

@@ -12,37 +12,34 @@ 'use strict';

// looking for only appropriate dimension value
// for example, for 'country' file we should process only
// dimensions with 'is.country' field === 'TRUE'
if (dimensionsHash[dictKey][expectedField]) {
const dimensionTypeByMeasure =
dimensionsHash[dictKey][expectedField][shared.getDimensionType(measureRecord.fileName)];
if (dimensionTypeByMeasure.toLowerCase() !== 'true') {
return;
}
}
if (!expectedField) {
errors.push({
folderPath: measureRecord.folderPath,
fileName: measureRecord.fileName,
entry: measureRecord.data,
errors: {
message: `Missing dimension: '${dictKey}' is absent.'`
}
});
errors.push(`Missing dimension: '${dictKey}' is absent.'`);
return;
}
if (expectedField && !dimensionsHash[dictKey][expectedField]) {
errors.push({
folderPath: measureRecord.folderPath,
fileName: measureRecord.fileName,
entry: measureRecord.data,
errors: {
message: `Unknown value: '${expectedField}' for dimension '${dictKey}'.`
}
});
errors.push(`Unknown value: '${expectedField}' for dimension '${dictKey}'.`);
return;
}
if (shared
.isExpectedDimension(
measureRecord.fileName,
dimensionsHash,
dictKey,
expectedField) === false) {
// for example, in case of we have 'ddf--data_for--gdp_const_ppp2011_dollar--by--country--year'
// but this file contains 'non-country' geo value (world_4region, for example)
errors.push(`Unexpected value: '${expectedField}' for dimension '${dictKey}'.`);
}
});
return errors;
return errors.map(error => {
return {
folderPath: measureRecord.folderPath,
fileName: measureRecord.fileName,
entry: measureRecord.data,
errors: {
message: error
}
};
});
}

@@ -49,0 +46,0 @@

@@ -1,5 +0,17 @@

exports.getDimensionType = (fileName) => {
// just from file for now
const splitted = fileName.split('--');
return splitted[splitted.length - 2];
};
const measureValuesValidatorSchema = require('../ddf-schema/ddf-measure-values.schema');
// looking for only appropriate dimension value
// for example, for 'country' file we should process only
// dimensions with 'is.country' field === 'TRUE'
exports.isExpectedDimension = (fileName, dimensionsHash, dictKey, expectedField) =>
measureValuesValidatorSchema
.dimensions(fileName)
.reduce((res, dimensionForTest) => {
const dimensionTypeByMeasure =
dimensionsHash[dictKey][expectedField][dimensionForTest];
if (dimensionTypeByMeasure && dimensionTypeByMeasure.toLowerCase() === 'true') {
res = true;
}
return res;
}, false);
{
"name": "ddf-validation",
"version": "0.3.0",
"version": "0.3.1",
"description": "DDF validion tool",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc