@contrail/transform-data 1.0.3 → 1.0.5

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.
@@ -1,2 +1,8 @@
1
1
  export declare class MapFileUtil {
2
+ private entities;
3
+ private cache;
4
+ constructor(entities: any);
5
+ getMapFile(fileId: string): Promise<any>;
6
+ getMappingSectionFromMap(mapFile: any, objectClass: string, direction: string): any;
7
+ getMappingSection(fileId: string, objectClass: string, direction: string): Promise<any>;
2
8
  }
@@ -2,5 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MapFileUtil = void 0;
4
4
  class MapFileUtil {
5
+ constructor(entities) {
6
+ this.entities = entities;
7
+ this.cache = {};
8
+ }
9
+ async getMapFile(fileId) {
10
+ if (this.cache[fileId]) {
11
+ return this.cache[fileId];
12
+ }
13
+ const options = {
14
+ entityName: 'file',
15
+ id: fileId,
16
+ };
17
+ const file = await this.entities.get(options);
18
+ const downloadUrl = file['downloadUrl'];
19
+ const response = await fetch(downloadUrl);
20
+ const mappingFile = await response.json();
21
+ this.cache[fileId] = mappingFile;
22
+ return mappingFile;
23
+ }
24
+ getMappingSectionFromMap(mapFile, objectClass, direction) {
25
+ let mapping = undefined;
26
+ if (mapFile[objectClass]) {
27
+ const classMapping = mapFile[objectClass];
28
+ if (classMapping[direction]) {
29
+ mapping = classMapping[direction];
30
+ }
31
+ }
32
+ return mapping;
33
+ }
34
+ async getMappingSection(fileId, objectClass, direction) {
35
+ const map = await this.getMapFile(fileId);
36
+ const mapSection = this.getMappingSectionFromMap(map, objectClass, direction);
37
+ return mapSection;
38
+ }
5
39
  }
6
40
  exports.MapFileUtil = MapFileUtil;
@@ -1 +1 @@
1
- export * from './rekey-transform';
1
+ export * from './rekey-transformer';
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./rekey-transform"), exports);
17
+ __exportStar(require("./rekey-transformer"), exports);
@@ -0,0 +1,4 @@
1
+ export declare class RekeyTransformer {
2
+ static transformData(csvJSON: any[], federatedMappings: Record<string, string>, deleteOldKey?: boolean): any[];
3
+ static transformObject(row: any, federatedMappings: Record<string, string>, deleteOldKey?: boolean): any;
4
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RekeyTransformer = void 0;
4
+ class RekeyTransformer {
5
+ static transformData(csvJSON, federatedMappings, deleteOldKey = false) {
6
+ for (const row of csvJSON) {
7
+ RekeyTransformer.transformObject(row, federatedMappings, deleteOldKey);
8
+ }
9
+ return csvJSON;
10
+ }
11
+ static transformObject(row, federatedMappings, deleteOldKey = false) {
12
+ for (const [key, value] of Object.entries(federatedMappings)) {
13
+ if (!row[key] && value) {
14
+ row[key] = row[value];
15
+ }
16
+ }
17
+ if (deleteOldKey) {
18
+ for (const value of Object.values(federatedMappings)) {
19
+ delete row[value];
20
+ }
21
+ }
22
+ return row;
23
+ }
24
+ }
25
+ exports.RekeyTransformer = RekeyTransformer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/transform-data",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Libraries for transforming data",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -39,6 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@contrail/core": "1.5.56",
42
+ "@contrail/sdk": "^1.2.1",
42
43
  "@contrail/util": "^1.0.26",
43
44
  "node-fetch": "^2.6.0"
44
45
  }
@@ -1,3 +0,0 @@
1
- export declare class RekeyTransform {
2
- transformData(csvJSON: any[], federatedMappings: Record<string, string>, deleteOldKey?: boolean): any[];
3
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RekeyTransform = void 0;
4
- class RekeyTransform {
5
- transformData(csvJSON, federatedMappings, deleteOldKey = false) {
6
- for (const row of csvJSON) {
7
- for (const [key, value] of Object.entries(federatedMappings)) {
8
- if (!row[key] && row[value]) {
9
- row[key] = row[value];
10
- }
11
- }
12
- if (deleteOldKey) {
13
- for (const value of Object.values(federatedMappings)) {
14
- delete row[value];
15
- }
16
- }
17
- }
18
- return csvJSON;
19
- }
20
- }
21
- exports.RekeyTransform = RekeyTransform;