@vizabi/reader-ddfcsv 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.nyc_output/795caf0b3acca8aacbd9d932d086ab81.json +1 -0
  2. package/.nyc_output/b4e1a7f86ae858c85e0528842263588d.json +1 -0
  3. package/CHANGELOG.md +5 -0
  4. package/coverage/base.css +223 -0
  5. package/coverage/block-navigation.js +63 -0
  6. package/coverage/index.html +136 -0
  7. package/coverage/prettify.css +1 -0
  8. package/coverage/prettify.js +1 -0
  9. package/coverage/sort-arrow-sprite.png +0 -0
  10. package/coverage/sorter.js +158 -0
  11. package/coverage/src/ddf-csv.ts.html +2685 -0
  12. package/coverage/src/ddfcsv-error.ts.html +132 -0
  13. package/coverage/src/ddfcsv-reader.ts.html +489 -0
  14. package/coverage/src/file-readers/backend-file-reader.ts.html +159 -0
  15. package/coverage/src/file-readers/github-path-adapter.ts.html +228 -0
  16. package/coverage/src/file-readers/index.html +110 -0
  17. package/coverage/src/index.html +136 -0
  18. package/coverage/src/index.ts.html +114 -0
  19. package/coverage/src/resource-selection-optimizer/in-clause-under-conjunction.ts.html +918 -0
  20. package/coverage/src/resource-selection-optimizer/index.html +110 -0
  21. package/coverage/src/resource-selection-optimizer/index.ts.html +102 -0
  22. package/coverage/src/test-cases/concepts.ts.html +150 -0
  23. package/coverage/src/test-cases/entities.ts.html +225 -0
  24. package/coverage/src/test-cases/index.html +110 -0
  25. package/dist/reader-ddfcsv-polyfill.js +1 -16
  26. package/dist/reader-ddfcsv-polyfill.js.map +1 -1
  27. package/dist/reader-ddfcsv.js +1 -16
  28. package/dist/reader-ddfcsv.js.map +1 -1
  29. package/lib/src/ddf-csv.js +16 -18
  30. package/lib/src/ddf-csv.js.map +1 -1
  31. package/lib/src/ddfcsv-error.js +1 -0
  32. package/lib/src/ddfcsv-error.js.map +1 -1
  33. package/lib/src/ddfcsv-reader.d.ts +1 -0
  34. package/lib/src/ddfcsv-reader.js +10 -5
  35. package/lib/src/ddfcsv-reader.js.map +1 -1
  36. package/lib/src/file-readers/backend-file-reader.d.ts +1 -1
  37. package/lib/src/file-readers/backend-file-reader.js +3 -2
  38. package/lib/src/file-readers/backend-file-reader.js.map +1 -1
  39. package/lib/src/file-readers/github-path-adapter.d.ts +1 -0
  40. package/lib/src/file-readers/github-path-adapter.js +46 -0
  41. package/lib/src/file-readers/github-path-adapter.js.map +1 -0
  42. package/lib/src/index.d.ts +0 -2
  43. package/lib/src/index.js +5 -8
  44. package/lib/src/index.js.map +1 -1
  45. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +1 -0
  46. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js +37 -12
  47. package/lib/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
  48. package/lib/src/resource-selection-optimizer/index.js +1 -0
  49. package/lib/src/resource-selection-optimizer/index.js.map +1 -1
  50. package/lib-web/src/ddf-csv.js +39 -41
  51. package/lib-web/src/ddf-csv.js.map +1 -1
  52. package/lib-web/src/ddfcsv-error.js +2 -1
  53. package/lib-web/src/ddfcsv-error.js.map +1 -1
  54. package/lib-web/src/ddfcsv-reader.d.ts +1 -0
  55. package/lib-web/src/ddfcsv-reader.js +17 -12
  56. package/lib-web/src/ddfcsv-reader.js.map +1 -1
  57. package/lib-web/src/file-readers/frontend-file-reader.js +3 -2
  58. package/lib-web/src/file-readers/frontend-file-reader.js.map +1 -1
  59. package/lib-web/src/file-readers/github-path-adapter.d.ts +1 -0
  60. package/lib-web/src/file-readers/github-path-adapter.js +46 -0
  61. package/lib-web/src/file-readers/github-path-adapter.js.map +1 -0
  62. package/lib-web/src/index-web.js +4 -3
  63. package/lib-web/src/index-web.js.map +1 -1
  64. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.d.ts +1 -0
  65. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js +53 -28
  66. package/lib-web/src/resource-selection-optimizer/in-clause-under-conjunction.js.map +1 -1
  67. package/lib-web/src/resource-selection-optimizer/index.js +1 -0
  68. package/lib-web/src/resource-selection-optimizer/index.js.map +1 -1
  69. package/package.json +5 -4
  70. package/src/ddf-csv.ts +11 -10
  71. package/src/ddfcsv-reader.ts +7 -3
  72. package/src/file-readers/backend-file-reader.ts +2 -2
  73. package/src/file-readers/frontend-file-reader.ts +3 -3
  74. package/src/file-readers/github-path-adapter.ts +53 -0
  75. package/src/index.ts +0 -5
  76. package/src/resource-selection-optimizer/in-clause-under-conjunction.ts +40 -12
  77. package/tsconfig-web.json +4 -1
  78. package/tsconfig.json +1 -1
  79. package/lib/src/file-readers/github-file-reader.d.ts +0 -7
  80. package/lib/src/file-readers/github-file-reader.js +0 -13
  81. package/lib/src/file-readers/github-file-reader.js.map +0 -1
  82. package/src/file-readers/github-file-reader.ts +0 -36
@@ -19,6 +19,7 @@ const JOIN_KEYWORD = 'join';
19
19
  const KEY_IN = '$in';
20
20
  const KEY_NIN = '$nin';
21
21
  const KEY_AND = '$and';
22
+ const KEY_OR = '$or';
22
23
 
23
24
  const getFirstConditionClause = clause => head(values(clause));
24
25
  const getFirstKey = obj => head(keys(obj));
@@ -45,8 +46,9 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
45
46
 
46
47
  const relatedFeatures = compact(featureDetectors.map(detector => detector(this.query, this.conceptsLookup)));
47
48
 
48
- return includes(relatedFeatures, QueryFeature.WhereClauseBasedOnConjunction) &&
49
- includes(relatedFeatures, QueryFeature.ConjunctionPartFromWhereClauseCorrespondsToJoin);
49
+ return this.query.from === "datapoints";
50
+ // return includes(relatedFeatures, QueryFeature.WhereClauseBasedOnConjunction) &&
51
+ // includes(relatedFeatures, QueryFeature.ConjunctionPartFromWhereClauseCorrespondsToJoin);
50
52
  }
51
53
 
52
54
  async getRecommendedFilesSet(): Promise<string[]> {
@@ -81,7 +83,17 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
81
83
 
82
84
  private fillResourceToFileHash(): InClauseUnderConjunction {
83
85
  this.flow.resourceToFile = get(this.datapackage, 'resources', []).reduce((hash, resource) => {
84
- hash.set(resource.name, resource.path);
86
+ const constraints = resource.schema.fields.reduce((result, field) => {
87
+ if (field.constraints?.enum) {
88
+ result.set(field.name, field.constraints.enum);
89
+ }
90
+ return result;
91
+ }, new Map())
92
+
93
+ hash.set(resource.name, {
94
+ path: resource.path,
95
+ constraints
96
+ });
85
97
 
86
98
  return hash;
87
99
  }, new Map());
@@ -99,6 +111,8 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
99
111
 
100
112
  if (this.singleAndField(where)) {
101
113
  this.flow.processableClauses.push(...flattenDeep(where[KEY_AND].map(el => this.getProcessableClauses(el))));
114
+ } else if (this.singleOrField(where)) {
115
+ this.flow.processableClauses.push(...flattenDeep(where[KEY_OR].map(el => this.getProcessableClauses(el))));
102
116
  } else {
103
117
  this.flow.processableClauses.push(...this.getProcessableClauses(where));
104
118
  }
@@ -108,7 +122,7 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
108
122
  }
109
123
 
110
124
  private collectEntityFilesNames(): InClauseUnderConjunction {
111
- this.flow.entityFilesNames = [];
125
+ this.flow.entityFilesNames = new Set();
112
126
  this.flow.fileNameToPrimaryKeyHash = new Map();
113
127
 
114
128
  for (const schemaResourceRecord of this.datapackage.ddfSchema.entities) {
@@ -117,9 +131,9 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
117
131
 
118
132
  if (head(schemaResourceRecord.primaryKey) === primaryKey) {
119
133
  for (const resourceName of schemaResourceRecord.resources) {
120
- const file = this.flow.resourceToFile.get(resourceName);
134
+ const file = this.flow.resourceToFile.get(resourceName).path;
121
135
 
122
- this.flow.entityFilesNames.push(file);
136
+ this.flow.entityFilesNames.add(file);
123
137
  this.flow.fileNameToPrimaryKeyHash.set(file, primaryKey);
124
138
  }
125
139
  }
@@ -131,7 +145,7 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
131
145
 
132
146
  private collectEntities(): Promise<any> {
133
147
  const self = this;
134
- const actions = self.flow.entityFilesNames.map(file => new Promise((actResolve, actReject) => {
148
+ const actions = [...self.flow.entityFilesNames].map(file => new Promise((actResolve, actReject) => {
135
149
  self.fileReader.readText(path.join(self.datasetPath, file), (err, text) => {
136
150
  if (err) {
137
151
  return actReject(err);
@@ -160,13 +174,14 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
160
174
  for (const entityFileDescriptor of entitiesData) {
161
175
  for (const entityRecord of entityFileDescriptor.result.data) {
162
176
  const primaryKeyForThisFile = this.flow.fileNameToPrimaryKeyHash.get(entityFileDescriptor.file);
163
- const primaryKeyCellValue = entityRecord[primaryKeyForThisFile];
164
177
  const domainsForCurrentRecord = [...getSubdomainsFromRecord(entityRecord)];
165
178
 
166
179
  if (isEmpty(domainsForCurrentRecord)) {
167
180
  domainsForCurrentRecord.push(primaryKeyForThisFile);
168
181
  }
169
182
 
183
+ const primaryKeyCellValue = entityRecord[primaryKeyForThisFile] || entityRecord[domainsForCurrentRecord[0]];
184
+
170
185
  this.flow.entityValueToDomainHash.set(primaryKeyCellValue, domainsForCurrentRecord);
171
186
  this.flow.entityValueToFileHash.set(primaryKeyCellValue, entityFileDescriptor.file);
172
187
  }
@@ -191,7 +206,7 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
191
206
 
192
207
  for (const clause of this.flow.processableClauses) {
193
208
  const filesGroupByClause = {
194
- entities: new Set(),
209
+ entities: this.flow.entityFilesNames,
195
210
  datapoints: new Set(),
196
211
  concepts: new Set()
197
212
  };
@@ -199,15 +214,24 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
199
214
  const entityValuesFromClause = firstConditionClause[KEY_IN] || getEntitiesExcept(firstConditionClause[KEY_NIN]);
200
215
 
201
216
  for (const entityValueFromClause of entityValuesFromClause) {
202
- filesGroupByClause.entities.add(this.flow.entityValueToFileHash.get(entityValueFromClause));
217
+ //filesGroupByClause.entities.add(this.flow.entityValueToFileHash.get(entityValueFromClause));
203
218
 
204
219
  const entitiesByQuery = this.flow.entityValueToDomainHash.get(entityValueFromClause);
205
220
 
206
221
  for (const entityByQuery of entitiesByQuery) {
207
222
  for (const schemaResourceRecord of this.datapackage.ddfSchema.datapoints) {
208
223
  for (const resourceName of schemaResourceRecord.resources) {
224
+ const file = this.flow.resourceToFile.get(resourceName);
209
225
  if (includes(schemaResourceRecord.primaryKey, entityByQuery)) {
210
- filesGroupByClause.datapoints.add(this.flow.resourceToFile.get(resourceName));
226
+ const constraint = file.constraints.get(entityByQuery);
227
+ if ( constraint ) {
228
+ if (constraint.includes(entityValueFromClause)) {
229
+ filesGroupByClause.datapoints.add(file.path);
230
+ }
231
+ }
232
+ else {
233
+ filesGroupByClause.datapoints.add(file.path);
234
+ }
211
235
  }
212
236
  }
213
237
  }
@@ -216,7 +240,7 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
216
240
 
217
241
  for (const schemaResourceRecord of this.datapackage.ddfSchema.concepts) {
218
242
  for (const resourceName of schemaResourceRecord.resources) {
219
- filesGroupByClause.concepts.add(this.flow.resourceToFile.get(resourceName));
243
+ filesGroupByClause.concepts.add(this.flow.resourceToFile.get(resourceName).path);
220
244
  }
221
245
  }
222
246
 
@@ -280,4 +304,8 @@ export class InClauseUnderConjunction implements IResourceSelectionOptimizer {
280
304
  private singleAndField(clause): boolean {
281
305
  return isOneKeyBased(clause) && !!get(clause, KEY_AND);
282
306
  }
307
+
308
+ private singleOrField(clause): boolean {
309
+ return isOneKeyBased(clause) && !!get(clause, KEY_OR);
310
+ }
283
311
  }
package/tsconfig-web.json CHANGED
@@ -18,8 +18,11 @@
18
18
  "importHelpers": true,
19
19
  "strictNullChecks": false,
20
20
  "baseUrl": ".",
21
+ "paths": {
22
+ "tslib" : ["node_modules/tslib/tslib.d.ts"]
23
+ },
21
24
  "lib": [
22
- "es2017",
25
+ "es2020",
23
26
  "dom"
24
27
  ],
25
28
  "downlevelIteration": true
package/tsconfig.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "strictNullChecks": false,
20
20
  "baseUrl": ".",
21
21
  "lib": [
22
- "es2018",
22
+ "es2020",
23
23
  "dom"
24
24
  ]
25
25
  },
@@ -1,7 +0,0 @@
1
- import { IResourceRead } from '../interfaces';
2
- export declare class GithubFileReader implements IResourceRead {
3
- recordTransformer: Function;
4
- setRecordTransformer(recordTransformer: any): void;
5
- readText(filePath: any, onFileRead: any, options: object): void;
6
- checkFile(path: string): void;
7
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class GithubFileReader {
4
- setRecordTransformer(recordTransformer) {
5
- this.recordTransformer = recordTransformer;
6
- }
7
- readText(filePath, onFileRead, options) {
8
- }
9
- checkFile(path) {
10
- }
11
- }
12
- exports.GithubFileReader = GithubFileReader;
13
- //# sourceMappingURL=github-file-reader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"github-file-reader.js","sourceRoot":"","sources":["../../../src/file-readers/github-file-reader.ts"],"names":[],"mappings":";;AAuBA,MAAa,gBAAgB;IAG3B,oBAAoB,CAAC,iBAAiB;QACpC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAe;IAC9C,CAAC;IAED,SAAS,CAAC,IAAY;IACtB,CAAC;CACF;AAZD,4CAYC"}
@@ -1,36 +0,0 @@
1
- /* tslint:disable */
2
-
3
- // import * as https from 'https';
4
-
5
- /*
6
- function readViaHttp(filePath: string, onFileRead: Function) {
7
- let content: string = '';
8
-
9
- https.get(filePath, res => {
10
- res.on('data', chunk => {
11
- content += chunk;
12
- });
13
- res.on('end', () => {
14
- onFileRead(null, content);
15
- });
16
- }).on('error', error => {
17
- onFileRead(error);
18
- });
19
- }
20
- */
21
-
22
- import { IResourceRead } from '../interfaces';
23
-
24
- export class GithubFileReader implements IResourceRead {
25
- public recordTransformer: Function;
26
-
27
- setRecordTransformer(recordTransformer) {
28
- this.recordTransformer = recordTransformer;
29
- }
30
-
31
- readText(filePath, onFileRead, options: object) {
32
- }
33
-
34
- checkFile(path: string) {
35
- }
36
- }