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

git-csv-diff

Package Overview
Dependencies
Maintainers
7
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-csv-diff - npm Package Compare versions

Comparing version 1.3.1 to 1.3.3

15

package.json
{
"name": "git-csv-diff",
"author": "Valor-Software",
"version": "1.3.1",
"version": "1.3.3",
"license": "GPL-3.0",

@@ -26,17 +26,16 @@ "description": "Library generate difference between csv-files based on Git commit hash",

"test:e2e": "./node_modules/.bin/mocha test/e2e/*.js --reporter spec",
"test:unit": "istanbul --include-all-sources cover _mocha -- -R spec 'test/unit/*.spec.js'"
"test:unit": "istanbul --include-all-sources cover _mocha -- -R spec 'test/unit/**/*.spec.js'"
},
"dependencies": {
"async": "2.1.2",
"daff": "1.3.18",
"lodash": "4.16.6"
"async": "2.5.0",
"daff": "1.3.25",
"lodash": "4.17.4"
},
"devDependencies": {
"async": "2.1.2",
"byline": "5.0.0",
"chai": "3.5.0",
"istanbul": "0.4.5",
"mocha": "3.2.0",
"sinon": "^1.17.7"
"mocha": "3.5.0",
"sinon": "2.2.0"
}
}

@@ -20,4 +20,4 @@ 'use strict';

// metaData.fileName;
// metaData.fileModifier;
// metadata.fileName;
// metadata.fileModifier;

@@ -35,7 +35,8 @@ // dataDiff.from;

function _process(metaData, dataDiff, streams) {
function _process(metadata, dataDiff, streams) {
metaData = Object.assign({}, metaData, splitPrimaryKeysByPathToOldAndNew(metaData));
metadata = Object.assign({}, metadata, splitPrimaryKeysByPathToOldAndNew(metadata));
console.log('Processing file: ', metadata.fileName);
const isTranslations = diffHelpers.isLanguageFile(metaData.fileName);
const isTranslations = diffHelpers.isLanguageFile(metadata.fileName);
const baseStream = isTranslations ? streams.lang : streams.diff;

@@ -48,13 +49,11 @@

setMetaDataFile(modelResponse.metadata.file, metaData);
// setup response meta data - DON'T CHANGE THE ORDER
setMetaDataLanguage(modelResponse.metadata, metadata);
setMetaDataFile(modelResponse.metadata, metadata);
// validate input data
if (!isSchemaExists(modelResponse.metadata) || !isValidFilePath(metaData.fileName)) {
if (!isSchemaExists(modelResponse.metadata)) {
console.error('Given schema doesn\'t exist!', JSON.stringify(modelResponse.metadata, null, '\t'));
return;
}
// setup response meta data
setMetaDataType(modelResponse.metadata);
setMetaDataLanguage(modelResponse.metadata, metaData.fileName);

@@ -64,3 +63,3 @@ /* Process Diff by Daff */

const diffResult = initDaffDiff(dataDiff);
// console.log(diffResult);
console.log(diffResult);

@@ -75,3 +74,3 @@ /* Main flow */

// setup `removedColumns` for files that are not removed
if (metaData.fileModifier != "D") {
if (metadata.fileModifier != "D") {
modelResponse.metadata.removedColumns = _.clone(modelDiff.header.remove);

@@ -91,3 +90,3 @@ }

const diffInstance = diffStrategy.get(modificationType);
diffInstance.process(baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue);
diffInstance.process(baseStream, metadata, modelResponse, modelDiff, diffResultColumns, rowValue);
}

@@ -99,3 +98,3 @@ // if nothing changed

const diffInstance = diffStrategy.get(diffModifiers.COLUMN_CREATE);
diffInstance.process(baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue);
diffInstance.process(baseStream, metadata, modelResponse, modelDiff, diffResultColumns, rowValue);
}

@@ -105,3 +104,3 @@ // Case: columns were renamed

const diffInstance = diffStrategy.get(diffModifiers.COLUMN_UPDATE);
diffInstance.process(baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue);
diffInstance.process(baseStream, metadata, modelResponse, modelDiff, diffResultColumns, rowValue);
}

@@ -111,3 +110,3 @@ // Case: columns were removed

const diffInstance = diffStrategy.get(diffModifiers.COLUMN_REMOVE);
diffInstance.process(baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue);
diffInstance.process(baseStream, metadata, modelResponse, modelDiff, diffResultColumns, rowValue);
}

@@ -121,8 +120,5 @@ }

function isValidFilePath(filename) {
return (_.includes(filename, "/") && !diffHelpers.isLanguageFile(filename)) ? false : true;
}
function setMetaDataLanguage(metaData, fileName) {
function setMetaDataLanguage(metadataModel, metadata) {
let lang = 'default';
const fileName = metadata.fileName;
if (diffHelpers.isLanguageFile(fileName)) {

@@ -132,14 +128,15 @@ const regexpRes = /lang\/(.+)\//.exec(fileName);

}
metaData.lang = lang;
_.extend(metadataModel, {lang});
}
function setMetaDataFile(file, metaData) {
const fileName = path.parse(metaData.fileName).base;
const resourcesByPathOld = _.keyBy(metaData.datapackage.old.resources, 'path');
file.old = resourcesByPathOld[fileName];
function setMetaDataFile(metadataModel, metadata) {
const fileName = diffHelpers.getOriginalFileName(metadata.fileName, metadataModel.lang);
const resourcesByPathOld = _.keyBy(metadata.datapackage.old.resources, 'path');
metadataModel.file.old = _.get(resourcesByPathOld, fileName);
// info is not available if file was removed
if (metaData.fileModifier != "D") {
const resourcesByPathNew = _.keyBy(metaData.datapackage.new.resources, 'path');
file.new = resourcesByPathNew[fileName];
if (metadata.fileModifier != "D") {
const resourcesByPathNew = _.keyBy(metadata.datapackage.new.resources, 'path');
metadataModel.file.new = _.get(resourcesByPathNew, fileName, {});
}

@@ -153,3 +150,3 @@ }

function setMetaDataType(metadata) {
function setMetaDataType(metadataModel) {
const constants = {

@@ -160,11 +157,11 @@ DATAPOINTS: 'datapoints',

};
const primaryKeys = diffHelpers.getPrimaryKeys(metadata);
const primaryKeys = diffHelpers.getPrimaryKeys(metadataModel);
if (primaryKeys.length > 1)
return metadata.type = constants.DATAPOINTS;
return metadataModel.type = constants.DATAPOINTS;
if (_.includes(constants.CONCEPTS, _.first(primaryKeys)))
return metadata.type = constants.CONCEPTS;
return metadataModel.type = constants.CONCEPTS;
return metadata.type = constants.ENTITIES;
return metadataModel.type = constants.ENTITIES;
}

@@ -171,0 +168,0 @@

@@ -25,3 +25,3 @@ 'use strict';

const isTranslations = diffHelpers.isLanguageFile(metaData.fileName);
const isDataPointsFile = diffHelpers.isDatapointFile(metaData);
const isDataPointsFile = diffHelpers.isDatapointFile({lang: modelResponse.metadata.lang, fileName: metaData.fileName, primaryKeyByPath: metaData.primaryKeyByPath});

@@ -28,0 +28,0 @@ if(isDataPointsFile && isTranslations) {

@@ -11,6 +11,6 @@ 'use strict';

diffHelpers.prototype.getPrimaryKeys = function (metadata) {
diffHelpers.prototype.getPrimaryKeys = function (metadataModel) {
// detect schema from `old` file if it was removed and not exists in `new`
const schemaSource = metadata.file.new ? metadata.file.new : metadata.file.old;
const primaryKeyRaw = _.clone(schemaSource.schema.primaryKey);
const schemaSource = metadataModel.file.new ? metadataModel.file.new : metadataModel.file.old;
const primaryKeyRaw = _.clone(_.get(schemaSource, 'schema.primaryKey', null));

@@ -22,3 +22,3 @@ return _.isString(primaryKeyRaw) ? [primaryKeyRaw] : primaryKeyRaw;

diffHelpers.prototype.isDatapointFile = function (metadata) {
const fileName = this.isLanguageFile(metadata.fileName) ? _.last(_.split(metadata.fileName, '/')) : metadata.fileName;
const fileName = this.getOriginalFileName(metadata.fileName, metadata.lang);

@@ -33,2 +33,8 @@ const primaryKeyByPath = _.get(metadata, 'primaryKeyByPath');

diffHelpers.prototype.getOriginalFileName = function (fileName, lang) {
if (this.isLanguageFile(fileName))
return _.replace(fileName, `lang/${lang}/`, '');
return fileName;
};
diffHelpers.prototype.isLanguageFile = function (filename) {

@@ -35,0 +41,0 @@ return _.includes(filename, "lang/");

@@ -28,3 +28,3 @@ 'use strict';

const isDataPointsFile = diffHelpers.isDatapointFile(metaData);
const isDataPointsFile = diffHelpers.isDatapointFile({lang: modelResponse.metadata.lang, fileName: metaData.fileName, primaryKeyByPath: metaData.primaryKeyByPath});
const isTranslations = diffHelpers.isLanguageFile(metaData.fileName);

@@ -34,3 +34,3 @@

const modificationSeparatorPosition = valueCell.indexOf('->');
const modificationSeparatorPosition = typeof valueCell === 'undefined' ? -1 : valueCell.indexOf('->');
const columnValue = diffResultColumns[indexCell];

@@ -37,0 +37,0 @@

@@ -19,3 +19,3 @@ 'use strict';

diffRowRemove.prototype.process = function (baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue) {
const isDataPointsFile = diffHelpers.isDatapointFile(metaData);
const isDataPointsFile = diffHelpers.isDatapointFile({lang: modelResponse.metadata.lang, fileName: metaData.fileName, primaryKeyByPath: metaData.primaryKeyByPath});

@@ -22,0 +22,0 @@ const primaryKey = _.first(diffHelpers.getPrimaryKeys(modelResponse.metadata));

const expect = require("chai").expect;
const sinon = require("sinon");
const _ = require("lodash");

@@ -40,3 +41,3 @@ const testFile = require("../../src/diff/header-remove");

file: {old: {schema: {primaryKey: 'column 1'}}, new: {schema: {primaryKey: 'column 2'}}},
fileName: '/lang/nl-nl/ddf--datapoints--lines.csv'
fileName: 'lang/nl-nl/ddf--datapoints--lines.csv'
};

@@ -68,6 +69,7 @@ const modelDiff = ModelDiff.init();

const diffHelpersStub = sinon.stub(diffHelpers, "writeToStream");
const metadata = _.defaults({lang: 'nl-nl'}, metaDataDatapoint);
const modelResponse = ModelResponse.init();
modelResponse.metadata.file.new = metaDataDatapoint.file.new;
modelResponse.metadata.file.old = metaDataDatapoint.file.old;
modelResponse.metadata.lang = metadata.lang;

@@ -89,3 +91,3 @@ const resultFixture = {

},
"lang": null,
"lang": metadata.lang,
"onlyColumnsRemoved": true,

@@ -109,3 +111,3 @@ "removedColumns": [],

testFile.process(baseStream, metaDataDatapoint, modelResponse, modelDiff, diffResultColumns, rowValue);
testFile.process(baseStream, metadata, modelResponse, modelDiff, diffResultColumns, rowValue);
sinon.assert.calledOnce(diffHelpersStub);

@@ -112,0 +114,0 @@ expect(diffHelpersStub.getCall(0).args[1]).to.deep.equal(resultFixture);

@@ -12,6 +12,6 @@ const expect = require("chai").expect;

const metadata = {file: {new: {schema: {primaryKey: ['pk1']}}}};
const metadataModel = {file: {new: {schema: {primaryKey: ['pk1']}}}};
const resultFixture = ['pk1'];
const result = testFile.getPrimaryKeys(metadata);
const result = testFile.getPrimaryKeys(metadataModel);
expect(result).to.deep.equal(resultFixture);

@@ -24,6 +24,6 @@

const metadata = {file: {old: {schema: {primaryKey: ['pk1']}}}};
const metadataModel = {file: {old: {schema: {primaryKey: ['pk1']}}}};
const resultFixture = ['pk1'];
const result = testFile.getPrimaryKeys(metadata);
const result = testFile.getPrimaryKeys(metadataModel);
expect(result).to.deep.equal(resultFixture);

@@ -36,6 +36,6 @@

const metadata = {file: {old: {schema: {primaryKey: ['pk1']}}, new: {schema: {primaryKey: ['pk2']}}}};
const metadataModel = {file: {old: {schema: {primaryKey: ['pk1']}}, new: {schema: {primaryKey: ['pk2']}}}};
const resultFixture = ['pk2'];
const result = testFile.getPrimaryKeys(metadata);
const result = testFile.getPrimaryKeys(metadataModel);
expect(result).to.deep.equal(resultFixture);

@@ -48,6 +48,6 @@

const metadata = {file: {new: {schema: {primaryKey: 'pk1'}}}};
const metadataModel = {file: {new: {schema: {primaryKey: 'pk1'}}}};
const resultFixture = ['pk1'];
const result = testFile.getPrimaryKeys(metadata);
const result = testFile.getPrimaryKeys(metadataModel);
expect(result).to.deep.equal(resultFixture);

@@ -60,6 +60,6 @@

const metadata = {file: {old: {schema: {primaryKey: 'pk1'}}}};
const metadataModel = {file: {old: {schema: {primaryKey: 'pk1'}}}};
const resultFixture = ['pk1'];
const result = testFile.getPrimaryKeys(metadata);
const result = testFile.getPrimaryKeys(metadataModel);
expect(result).to.deep.equal(resultFixture);

@@ -72,6 +72,6 @@

const metadata = {file: {old: {schema: {primaryKey: 'pk1'}}, new: {schema: {primaryKey: 'pk2'}}}};
const metadataModel = {file: {old: {schema: {primaryKey: 'pk1'}}, new: {schema: {primaryKey: 'pk2'}}}};
const resultFixture = ['pk2'];
const result = testFile.getPrimaryKeys(metadata);
const result = testFile.getPrimaryKeys(metadataModel);
expect(result).to.deep.equal(resultFixture);

@@ -92,3 +92,4 @@

}
}
},
lang: 'default'
};

@@ -135,3 +136,4 @@

}
}
},
lang: 'path'
};

@@ -138,0 +140,0 @@

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