Skip to content

Commit

Permalink
feat(load-file): add load file function to ddfcsv-reader
Browse files Browse the repository at this point in the history
  • Loading branch information
korel-san committed Oct 3, 2018
1 parent 0fd7695 commit 804fa6a
Show file tree
Hide file tree
Showing 23 changed files with 574 additions and 601 deletions.
23 changes: 0 additions & 23 deletions dist/vizabi-ddfcsv-reader.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/vizabi-ddfcsv-reader.js.map

This file was deleted.

3 changes: 2 additions & 1 deletion lib/src/ddfcsv-reader.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { IReader } from './interfaces';
export declare function prepareDDFCsvReaderObject(defaultFileReader?: IReader): (externalFileReader?: IReader, logger?: any) => {
init(readerInfo: any): void;
getAsset(asset: any): Promise<{}>;
getFile(filePath: string, isJsonFile: boolean): Promise<any>;
getAsset(assetPath: any): Promise<any>;
read(queryParam: any, parsers: any): Promise<any>;
_prettifyData(data: any, parsers: any): any;
};
29 changes: 14 additions & 15 deletions lib/src/ddfcsv-reader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/ddfcsv-reader.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/src/test-cases/concepts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/src/test-cases/entities.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions lib/test/definition/test-cases/concepts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export declare const description = "Autogenerated tests for concepts";
export declare const initData: {};
export declare const testsDescriptors: {
[description]: {
itTitle: string;
query: {
repositoryPath: string;
dataset: string;
from: string;
select: {
key: string[];
};
where: {
concept: string;
};
};
}[];
};
1 change: 1 addition & 0 deletions lib/test/definition/test-cases/concepts.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/test/definition/test-cases/entities.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const initData: {};
export declare const testsDescriptors: {};
1 change: 1 addition & 0 deletions lib/test/definition/test-cases/entities.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"lodash.has": "4.5.2",
"lodash.head": "4.0.1",
"lodash.includes": "4.3.0",
"lodash.isarray": "4.0.0",
"lodash.isempty": "4.4.0",
"lodash.isnil": "4.0.0",
"lodash.isobject": "3.0.2",
Expand Down Expand Up @@ -107,7 +106,6 @@
"sinon": "6.1.4",
"source-map-loader": "0.2.3",
"source-map-support": "0.5.6",
"ts-babel-node": "1.1.1",
"ts-loader": "4.3.0",
"ts-node": "7.0.0",
"tslib": "1.9.3",
Expand Down
32 changes: 17 additions & 15 deletions src/ddfcsv-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,38 @@ export function prepareDDFCsvReaderObject (defaultFileReader?: IReader) {
this.reader = ddfCsvReader(this.logger);
},

async getAsset (asset) {
const isJsonAsset = asset.slice(-'.json'.length) === '.json';
const assetPath = `${this._basePath}/${asset}`;

async getFile (filePath: string, isJsonFile: boolean): Promise<any> {
return new Promise((resolve, reject) => {
this.fileReader.readText(assetPath, (err, data) => {
this.fileReader.readText(filePath, (err, data) => {
if (err) {
reject(err);
return;
return reject(err);
}

if (isJsonAsset) {
try {
resolve(JSON.parse(data));
} catch (jsonErr) {
reject(err);
try {
if (isJsonFile) {
return resolve(JSON.parse(data));
}
} else {
resolve(data);

return resolve(data);
} catch (jsonErr) {
return reject(jsonErr);
}
});
});
},

async getAsset (assetPath): Promise<any> {
const isJsonAsset = assetPath.slice(-'.json'.length) === '.json';

return await this.getFile(assetPath, isJsonAsset);
},

async read (queryParam, parsers) {
let result;

try {
result = await this.reader.query(queryParam, {
basePath: this._basePath,
basePath: queryParam.repositoryPath,
fileReader: this.fileReader,
logger: this.logger,
conceptsLookup: new Map<string, any>()
Expand Down
5 changes: 3 additions & 2 deletions src/test-cases/concepts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import * as path from 'path';
const ALL_CONCEPTS: string[] = [ '', ' ', RESERVED_CONCEPT, RESERVED_CONCEPT_TYPE, RESERVED_DOMAIN, RESERVED_DRILL_UP, 'company', 'english_speaking', 'company_scale', 'name', 'anno', 'lines_of_code', 'region', 'country', 'latitude', 'longitude', 'full_name_changed', 'project', 'additional_column', 'meeting_style', 'popular_appeal', 'methodology' ];

export const description = 'Autogenerated tests for concepts';
export const initData = { path: path.join(BASE_PATH, WS_TESTING_PATH, 'master-HEAD') };
export const initData = { };
export const testsDescriptors = {
[description]: ALL_CONCEPTS.map((concept: string) => ({
itTitle: `should be fine for concept '${concept}'`,
query: {
from: 'concepts',
repositoryPath: path.join(BASE_PATH, WS_TESTING_PATH, 'master-HEAD'),
dataset: WS_TESTING_PATH,
from: 'concepts',
select: {key: ['concept']},
where: {
concept
Expand Down
5 changes: 3 additions & 2 deletions src/test-cases/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ALL_OPERATORS: string[] = [null, '.', '.is--'];
const ALL_CONCEPTS: string[] = ['', ' ', RESERVED_CONCEPT, RESERVED_CONCEPT_TYPE, RESERVED_DOMAIN, RESERVED_DRILL_UP, 'company', 'english_speaking', 'company_scale', 'name', 'anno', 'lines_of_code', 'region', 'country', 'latitude', 'longitude', 'full_name_changed', 'project', 'domain', 'additional_column', 'meeting_style', 'popular_appeal', 'methodology'];
const ALL_ENTITY_SETS_AND_DOMAINS: string[] = ['company', 'english_speaking', 'company_scale', 'region', 'project'];

export const initData = {path: BASE_PATH + WS_TESTING_PATH + '/master-HEAD'};
export const initData = {};
export const testsDescriptors = ALL_ENTITY_SETS_AND_DOMAINS.reduce((acc, entitySetOrDomain: string) => {
const BINARY_OPERATORS = [...flatMap(ALL_CONCEPTS, (parent: string) => map(ALL_CONCEPTS, (child) => [parent, child]))];
const UNARY_OPERATORS = [...ALL_CONCEPTS];
Expand All @@ -36,8 +36,9 @@ export const testsDescriptors = ALL_ENTITY_SETS_AND_DOMAINS.reduce((acc, entityS
return CONCEPTS_CLAUSE.map((clause: string) => ({
itTitle: `should be fine for ${clause}`,
query: {
from: 'entities',
repositoryPath: BASE_PATH + WS_TESTING_PATH + '/master-HEAD',
dataset: WS_TESTING_PATH,
from: 'entities',
select: {key: [entitySetOrDomain]},
where: {
[clause]: true
Expand Down
6 changes: 2 additions & 4 deletions test/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ describe('Assets functionality', () => {
const expectedAssetsData = require('./assets-fixtures/world-50m.json');
const reader = getDDFCsvReaderObject();

reader.init({
path: './test/assets-fixtures'
});
reader.init({});

const result = await reader.getAsset('world-50m.json');
const result = await reader.getAsset('./test/assets-fixtures/world-50m.json');

expect(result).to.deep.equal(expectedAssetsData);
});
Expand Down
Loading

0 comments on commit 804fa6a

Please sign in to comment.